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

Vue:全局组件与局部组件

时间:2017-08-30 20:52:04      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:alert   2.4   charset   vue   one   组件   new   code   button   

全局组件

<!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>

 

Vue:全局组件与局部组件

标签:alert   2.4   charset   vue   one   组件   new   code   button   

原文地址:http://www.cnblogs.com/c491873412/p/7455038.html

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