vue.js: [Vue warn]: Unknown custom element: <xxxx> - did you register the component correctly?

我的原错误为:
vue.js:634 [Vue warn]: Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the “name” option.
源码:

<!DOCTYPE html>
<html lang="ch">
<head>
    <meta charset="UTF-8">
    <title>parent</title>
</head>
<body>

<div id="app">
    <introduce :title="msg"></introduce>
    <hr>
    <forComponent :items="lessons"></forComponent>
</div>


<script src="node_modules/vue/dist/vue.js"></script>
<script>

    // 局部组件
    const introduce = {
        // 注意只能有一个根标签
        template: "<h1>{{title}}</h1>",
        props: ['title']
    };

    const forComponent = {
        template: "<ul><li v-for='item in items'>{{item}}</li></ul>",
        props: ['items']
    };

    new Vue({
        el: "#app",//element  vue作用的标签 它只能作用于el下的标签
        data: {
            msg: "hello everyone !",
            lessons: ["java", "php","python"],
        },
        components:{
            introduce,
            forComponent:forComponent,
        }
    });
</script>

</body>
</html>

错误原因:
HTML 中的标签名是大小写不敏感的,所以浏览器会把所有大写字符解释为小写字符。这意味着当你使用 DOM 中的模板时,使用驼峰命名法 的 prop 名需要使用其等价的短横线分隔命名方法或者全部使用小写。否者就会报上述错误。

改正后的代码:

<!DOCTYPE html>
<html lang="ch">
<head>
    <meta charset="UTF-8">
    <title>parent</title>
</head>
<body>

<div id="app">
    <introduce :title="msg"></introduce>
    <hr>
    <study :items="lessons"></study>
</div>


<script src="node_modules/vue/dist/vue.js"></script>
<script>

    // 局部组件
    const introduce = {
        // 注意只能有一个根标签
        template: "<h1>{{title}}</h1>",
        props: ['title']
    };

    const study = {
        template: "<ul><li v-for='item in items'>{{item}}</li></ul>",
        props: ['items']
    };

    new Vue({
        el: "#app",//element  vue作用的标签 它只能作用于el下的标签
        data: {
            msg: "hello everyone !",
            lessons: ["java", "php","python"],
        },
        components:{
            introduce,
            study:study,
        }
    });
</script>
</body>
</html>
  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值