zoukankan      html  css  js  c++  java
  • Vue:全局组件与局部组件

    全局组件

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <div id="seg1">
        <alert></alert>
    </div>
    
    <script src="https://cdn.bootcss.com/vue/2.4.2/vue.js"></script>
    <script>
        Vue.component(
            'alert',{
                template:
                    '<button @click="on_click">弹弹弹</button>'
                ,
                methods:{
                    on_click:function () {
                        alert('Yo.');
                    }
                }
            }
        );
        new Vue({
            el:"#seg1"
        })
    </script>
    </body>
    </html>

    局部组件

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <div id="seg1">
        <alert></alert>
    </div>
    
    <script src="https://cdn.bootcss.com/vue/2.4.2/vue.js"></script>
    <script>
       var alert_component={
                template:
                    '<button @click="on_click">弹弹弹</button>'
                ,
                methods:{
                    on_click:function () {
                        alert('Yo.');
                    }
                }
            };
    
        new Vue({
            el:"#seg1",
            componets:{
                alert:alert_component
            }
        })
    </script>
    </body>
    </html>
  • 相关阅读:
    CentOS
    Docker
    Chart的简单使用
    DataGridView中间插入数据行
    获取每个月的固定的第n个星期几
    设置只能开启一个程序实例
    DataContext与实体类
    Attribute
    Delegate
    Event
  • 原文地址:https://www.cnblogs.com/c491873412/p/7455038.html
Copyright © 2011-2022 走看看