vue学习问题总结(一)

  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>"
    });

     

posted @ 2017-11-28 18:17  mickey007  阅读(1014)  评论(0编辑  收藏  举报