vue学习问题总结(一)

简介: 使用comopontent组件报错错误信息:vue.js:491 [Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.
  1. 使用comopontent组件报错
    错误信息:vue.js:491 [Vue warn]: Unknown custom element: <todo-item> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
    代码:
    <p>
       使用component组件<br>
       <todo-item></todo-item>
    </p>
    Vue.component('todo-item',{
        template:'I am a component'
    });

    解决办法:将vue的全局注册提取到body的上面,html中就可以引用了

  2. 仍然使用上面的js代码,会报出第二个错误
    错误信息:Component template requires a root element, rather than just text.
    解决办法:错误提示中说组件模版中需要一个根元素,而不是文本,将里面的tempate增加html标签即可,更改完的代码
    Vue.component('todo-item',{
        template:"<li>I am a component</li>"
    });

     

开开心心编码,快快乐乐生活。
目录
相关文章
|
2天前
|
JavaScript
vue 函数化组件
vue 函数化组件
|
3天前
|
JavaScript
vue中watch的用法
vue中watch的用法
|
3天前
|
JavaScript 前端开发
vue动态添加style样式
vue动态添加style样式
|
3天前
|
JavaScript 前端开发
Vue项目使用px2rem
Vue项目使用px2rem
|
2天前
|
JavaScript API
vue学习(13)监视属性
vue学习(13)监视属性
13 2
|
2天前
|
JavaScript 前端开发
vue学习(15)watch和computed
vue学习(15)watch和computed
9 1
|
2天前
|
JavaScript
vue学习(14)深度监视
vue学习(14)深度监视
11 0
|
10天前
|
JavaScript
vue学习(4)数据绑定
vue学习(4)数据绑定
32 10
|
10天前
|
JavaScript 前端开发
vue学习(6)
vue学习(6)
31 9
|
10天前
|
JavaScript 开发者
vue学习(5)
vue学习(5)
25 7