【发布时间】:2018-06-07 12:04:01
【问题描述】:
我很难理解 VueJS 中的组件和模板系统。我下载了VuetifyJS PWA example template 并尝试将Hello.vue 的完整内容替换为VuetifyJS google-contacts.vue 示例模板的内容。
我在npm run dev 上localhost:8080 后收到此错误消息:
> vue.esm.js?65d7:578 [Vue warn]: Failed to mount component: template or render function not defined.
found in
---> <Hello> at /home/a/my-project/src/components/Hello.vue
<App> at /home/a/my-project/src/App.vue
<Root>
为什么不能只替换 <template></template> 内容,我需要更改什么才能使用 google-contacts.vue 模板内容而不是 Hello.vue 内容?
【问题讨论】:
-
据我所见,处理 Vue 组件通常有两种方式:1) 使用组件的
template属性的经典方式,以及 2) 导出单个组件和然后稍后导入它们。听起来第二个是你的目标,你做错了。不幸的是,我们无法确定是否是这种情况。请提供代码 sn-ps,以便我们更清楚地了解您的问题。 -
我链接了我在问题中使用的代码(粗体文本)和完整的模板。 (这些都是 VuetifyJS 的例子)
-
@ramazan793 我尝试了建议的解决方案,但没有奏效。错误:
<hello> - did you register the component correctly? For recursive components, make sure to provide the "name" option. found in ---> <App> at /home/a/my-project/src/App.vue <Root> -
@Tom 尝试在 main.js 中全局注册您的组件:
import Hello from '~/components/hello.vue' Vue.component('Hello', Hello);与该问题的第二个答案一样
标签: vue.js vuejs2 vue-component vuetify.js