Vue3 组件注册问题是 app.js

时间:2021-07-19 02:00:33

标签: vuejs3

我正在尝试在 app.js 中为 VUE 3 应用注册组件,如下所示:

import test1 from './components/test1.vue';
import test2 from './components/test2.vue';

createApp(test1).mount("#app").default;
createApp(test2).mount("#app").default;

但它给出了如下错误。如果我只显示一个组件,那么它工作正常。

Uncaught TypeError: Cannot read property 'nextSibling' of null
    at nextSibling (runtime-dom.esm-bundler.js:35)
    at removeFragment (runtime-core.esm-bundler.js:5719)
    at remove (runtime-core.esm-bundler.js:5685)
    at unmount (runtime-core.esm-bundler.js:5671)
    at unmountComponent (runtime-core.esm-bundler.js:5743)
    at unmount (runtime-core.esm-bundler.js:5644)
    at patch (runtime-core.esm-bundler.js:4642)
    at render (runtime-core.esm-bundler.js:5791)
    at mount (runtime-core.esm-bundler.js:4081)
    at Object.app.mount (runtime-dom.esm-bundler.js:1319)

我正在模板中访问它,如下所示:


    <div id="app">
                <test1>
                    <test2></test2>
                </test1>
    </div>

谁能建议我如何摆脱这个错误? 谢谢

1 个答案:

答案 0 :(得分:1)

要注册组件,请使用 App.component 方法而不是 createApp 方法,后者用于创建新的 Vue 实例。通常情况下,您会看到以下内容:

const app = createApp(...)

app.component("test1", test1)
app.component("test2", test2)

app.mount('#app')

您可以阅读有关组件注册 here 的更多信息。

相关问题