[Vue warn]: Unknown custom element: <component-name> - did you register the component correctly?

学习Vue碰到的一个错误。
[Vue warn]: Unknown custom element: - did
you register the component correctly? For recursive components,
make sure to provide the “name” option.
(found in )

懵。。。。。。。。。。。。。。。莫不是刚入门就劝退的节奏…
自己研究一下:

var vm = new Vue({
            el: "#app1",
            data:{
                message:"这是第一个Vue实例"
            }
        })
    // 定义组件
    Vue.component('component-name',{
        props: ['message'],
        template: '<li>{{message}}</li>'
    });

上面是简单的组件定义,一看完全没有问题。一运行就报错。
解决:1.组件定义和对象定义位置进行互换。
如下:

    Vue.component('component-name',{
        props: ['message'],
        template: '<li>{{message}}</li>'
    });
    var vm = new Vue({
            el: "#app1",
            data:{
                message:"这是第一个Vue实例"
            }
   })

2.看看自己在组件命名时是否是开头大写。有的时候,浏览器统一会按照小写处理,因为大小写找不到相应组件名错误。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值