longkas239
V2EX  ›  Vue.js

帮忙看看 Vue 的问题

  •  
  •   longkas239 · Dec 13, 2021 · 3575 views
    This topic created in 1791 days ago, the information mentioned may be changed or developed.

    环境 vite + vue3 + element plus, 组件中的两端 script 代码,这两处 setup 看日志有一处没有运行,是正常的吗,app 引用的时候提示找不到 "form"

    App.vue

    <script setup>
    	import moment from 'moment/min/moment-with-locales'
        import { ref, reactive, toRefs, toRef } from 'vue'
        console.log("setup from setup");
    </script>
    
    
    <script>
        import { reactive, toRefs } from 'vue';
        export default {
            setup() {
                console.log("setup from default");
                const state = reactive({
                    form: {
                        userName: '',
                        newPass: '',
                    }
                });
                return {
                    ...toRefs(state),
                }
            },
    </script>
    
    
    7 replies  •  2021-12-14 16:28:01 +08:00
    vacnt7
    vacnt7
    Dec 13, 2021
    1
    return 里面直接 return state 就好了,不是很清楚为什么还要再去 refs 一次 state ,上面的 reactive 已经将 form 初始化为响应式变量了
    chengxy
    chengxy
    Dec 13, 2021
    2
    @vacnt7 #1 估计是要解构,不想使用 state.form 的方式。
    dengshen
    dengshen
    Dec 14, 2021 via iPhone
    3
    默认导出覆盖 setup 了
    gouflv
    gouflv
    Dec 14, 2021 via iPhone❤️1
    4
    vue3 的代码风格一言难尽
    longkas239
    longkas239
    OP
    Dec 14, 2021 via Android
    6
    这个问题是解决了,但是后面遇到了诡异的其他 bug ,官方说两种 script 可以混用,但是 antd 和 elementplus 都不建议使用,我提 bug 到 vite 然后转到 element 再转到 vue ,对于使用者根本不知道问题会出现在哪一端,而且开发模式正常只有打包部署出问题,调试完这个程序我是不想碰前端项目或者考虑换个扎实点的前端框架了
    tolking
    tolking
    Dec 14, 2021
    7
    总有人不看文档.jpg
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2094 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 04:30 · PVG 12:30 · LAX 20:30 · JFK 23:30
    ♥ Do have faith in what you're doing.