- 使用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中就可以引用了
- 仍然使用上面的js代碼,會報出第二個錯誤
錯誤信息:Component template requires a root element, rather than just text.
解決辦法:錯誤提示中說組件模版中需要一個根元素,而不是文本,將里面的tempate增加html標簽即可,更改完的代碼Vue.component('todo-item',{template:"<li>I am a component</li>" });
?
轉載于:https://www.cnblogs.com/blueskyli/p/7911391.html