mixins

var  base = { //公用方法
    methods:{
        show:function(){
            this.visible = true
        },
        hide:function () {
            this.visible = false
        },
        toggle:function(){
            this.visible = !this.visible
        }
    },
    data:function () {
        return {
            visible : false
        }
    }
}

Vue.component('tooltip',{
    template:`
        <div>
        <span @mouseenter="show" @mouseleave="hide">byx</span>
        <div v-if="visible">表严肃</div>
</div>
    `,

    mixins:[base]
})
Vue.component('popup',{
    template:`
        <div>
            <button @click="toggle">popup</button>
            <div v-if="visible">
                <h4>title</h4>
                Stephen Hawking is one of the great scientists in the history, whose brilliant idea                           about universe opens the door for people to get to know the universe. Hawking is also
                a humorous person that he has showed in the movies and the public loved him so much.
                As a father, his suggestions to the children are very impressive. 
            </div>
        </div>
    `,
    mixins:[base],
    data:function () {
        return {
            visible :true
        }
    },
})


var app = new Vue({
    el:"#app",
    data:{

    },

})
阅读更多
上一篇自定义指令传参
下一篇vue-router
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭