小编pro*_*ova的帖子

为什么动态组件在vue3中不起作用?

这是一个有效的 Vue2 示例:

<template>
    <div>
        <h1>O_o</h1>
        <component :is="name"/>
        <button @click="onClick">Click me !</button>
    </div>
</template>

<script>
    export default {
        data: () => ({
            isShow: false
        }),
        computed: {
            name() {
                return this.isShow ? () => import('./DynamicComponent') : '';
            }
        },
        methods: {
            onClick() {
                this.isShow = true;
            }
        },
    }
</script>
Run Code Online (Sandbox Code Playgroud)

Vue3 下的 Redone 选项不起作用。没有发生错误,但组件没有出现。

<template>
    <div>
        <h1>O_o</h1>
        <component :is="state.name"/>
        <button @click="onClick">Click me !</button>
    </div>
</template>

<script>
    import {ref, reactive, computed} from 'vue'

    export default {
        setup() {
            const state = …
Run Code Online (Sandbox Code Playgroud)

vue.js vuejs3

9
推荐指数
1
解决办法
8471
查看次数

标签 统计

vue.js ×1

vuejs3 ×1