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>
    
  • 相关阅读:
    Python 双向链表的实现
    Python 单链表实现
    分享两种 Python 中的单例模式
    HTML 盒子模型
    HTML 行高
    HTML 超链接 文本修饰 背景属性
    HTML 标签分类
    HTML 文字,样式表
    HTML CSS
    HTML 锚点 空链 超链优化写法
  • 原文地址:https://www.cnblogs.com/jianjie/p/12606049.html
Copyright © 2011-2022 走看看