ltblll 2019-04-15 14:04 采纳率: 0%
浏览 504

请问各位大神,如下Vue的代码中为何这个局部组件无法使用??

代码如下:

//定义局部组件 const localcom = { template:"<button @click='msg++'>{{msg}}</button>", data(){ return{ msg:0 } } }; const app = new Vue({ el:"#app", comments:{ localcom } });


console中报错为
[Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option.
请各位大佬帮忙查看一下哪里有问题

  • 写回答

1条回答 默认 最新

  • 张清悠 2023-09-19 08:51
    关注

    comments 应该是 components,
    Vue 组件需要提供一个唯一的组件名。在局部组件中,没有提供组件名。请在局部组件中添加一个 name 选项,并为其指定一个唯一的组件名。

    // 定义局部组件
    const localcom = {
      name: 'localcom',
      template: "<button @click='msg++'>{{msg}}</button>",
      data() {
        return {
          msg: 0
        }
      }
    };
    
    const app = new Vue({
      el: "#app",
      components: {
        localcom
      }
    });
    
    
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办