码迷,mamicode.com
首页 > 其他好文 > 详细

组件-全局组件和局部组件

时间:2018-01-30 19:35:23      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:oct   meta   alert   pre   col   lib   component   .com   nts   

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

</head>
<body>
<div id="seg1">
    <alert></alert>
    <ttt></ttt>
</div>
<div id="seg2">
    <alert></alert>
    <ttt></ttt>
</div>
<div id="seg3">
    <texts></texts>
</div>


<script src="../lib/vue.js"></script>
<script src="js/main.js"></script>
</body>
</html>
Vue.component("ttt", {
    template: "<button @click=\"on_click\">全局弹弹弹</button>",
    methods: {
        on_click: function () {
            alert("Yo.")
        }
    }
});


var obj = {
    template: "<button @click=\"on_click\">全局弹弹弹</button>",
    methods: {
        on_click: function () {
            alert("Yo.")
        }
    }
}




new Vue({
    el: "#seg1",
    components: {
        "alert": {
            template: "<button @click=\"on_click\">弹弹弹</button>",
            methods: {
                on_click: function () {
                    alert("Yo.")
                }
            }
        }
    }
});
new Vue({
    el: "#seg2",
    components: {
        "alert": {
            template: "<button @click=\"on_click\">弹弹弹</button>",
            methods: {
                on_click: function () {
                    alert("点你大爷")
                }
            }
        }
    }
});
new Vue({
    el:"#seg3",
    components:{
        "texts":obj
    }
})

 

组件-全局组件和局部组件

标签:oct   meta   alert   pre   col   lib   component   .com   nts   

原文地址:https://www.cnblogs.com/52-qq/p/8386296.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!