zoukankan      html  css  js  c++  java
  • 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>
    
  • 相关阅读:
    Index(4.3)
    第七次会议(4.22)
    第六次会议(4.15)
    第五次会议(4.8)
    第四次会议(4.2)
    第三次会议(3.25)
    第二次扩大会议(3.19)
    第二次会议(3.25)
    第一次会议(3.11)
    牛客练习赛25A求1-x因数和(离散求和)
  • 原文地址:https://www.cnblogs.com/jianjie/p/12606049.html
Copyright © 2011-2022 走看看