当前位置: 代码迷 >> 综合 >> Vue组件报错For recursive components, make sure to provide the “name“ option.
  详细解决方案

Vue组件报错For recursive components, make sure to provide the “name“ option.

热度:102   发布时间:2023-11-30 21:11:55.0

在Vue的组件component学习中报错:

[Vue warn]: Unknown custom element: <teen> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
 

 

试了半天,竟然是js代码位置问题!

错误vue代码: 

 var vm = new Vue({el: "#app",data: {message: "b",items: [{message: "aaa"},{message: "bbb"},{message: "ccc"}]}});//组件必须定义在tmd Vue实例上边!!!Vue.component("teen",{props: ["msg"],template: "<li>{
   {msg.message}}</li>"});

将Vue.component放在Vue实例上,问题解决(无语)

Vue.component("teen",{props: ["msg"],template: "<li>{
   {msg.message}}</li>"});var vm = new Vue({el: "#app",data: {message: "b",items: [{message: "aaa"},{message: "bbb"},{message: "ccc"}]}});

运行结果:

 

  相关解决方案