vue组件命名和props命名

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Examples</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <!--  post-title使用驼峰命名postTitle会报错 blog-post改为blogPost会报错 -->
        <blog-post post-title="hello!"></blog-post>
    </div>



    <script>
        Vue.component('blog-post', { //命名时候可以使用横线
          props: ['postTitle'],                 //如果这里使用连接线post-title将报错
          template: '<h3>{{ postTitle }}</h3>'
        })

        new Vue({
            el:"#app",

        })
    </script>

</body>
</html>
    
总结 props里可使用驼峰命名但不能用横线,如果props使用驼峰 组件上将使用横线
vue组建命名 可以使用驼峰和横线, 如果使用驼峰 组建使用将采用横线使用

猜你喜欢

转载自www.cnblogs.com/yangjie-space/p/11441728.html