430 vue组件命名方式: 短横线、驼峰

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <!-- 在普通的标签模板中,推荐使用短横线的方式使用组件 -->
        <hello-world></hello-world>
        <p>---------------这里是分割线---------------</p>
        <button-counter></button-counter>
    </div>
    <script type="text/javascript" src="./vue.js"></script>
    <script type="text/javascript">
        /*
            组件命名方式: 短横线、驼峰
            Vue.component('my-component', {})
            Vue.component('MyComponent', {})
            如果使用驼峰式命名组件,那么在使用组件的时候,只能在字符串模板中用驼峰的方式使用组件,但是在普通的标签模板中,必须使用短横线的方式使用组件
        */

        Vue.component('HelloWorld', {
            template: '<div>{{msg}} --- 哈哈哈</div>',
            data() {
                return {
                    msg: 'HelloWorld'
                }
            }
        });

        Vue.component('button-counter', {
            template: `
                <div>
                    <button @click="handle">点击了{{count}}次</button>
                    <button>测试123</button>
                    <!-- 在字符串模板中用驼峰的方式使用组件 -->
                    <h3>下面是在字符串模板中用驼峰的方式使用组件</h3>
                    <HelloWorld></HelloWorld>
                </div>
            `,
            data() {
                return {
                    count: 0
                }
            },
            methods: {
                handle: function () {
                    this.count += 2;
                }
            }
        })

        var vm = new Vue({
            el: '#app',
            data: {

            }
        });
    </script>
</body>

</html>
原文地址:https://www.cnblogs.com/jianjie/p/12606049.html