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

组件-子父通信

时间:2018-01-30 19:52:29      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:click   mit   body   set   lib   vue   lang   type   log   

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

    </style>
</head>
<body>
<div id="app">
    <balance></balance>
</div>


<script src="../lib/vue.js"></script>
<script src="js/main.js"></script>
</body>
</html>
Vue.component("balance",{
    template:`
    <div>
        <show @show-balance="show_balance()"></show>
        <div v-if="show">
            您的余额是:$9999999!
        </div>
    </div>
    `,
    methods:{
        show_balance:function () {
            console.log("可以来")
            this.show = true
        }
    },
    data:function () {
        return {
            show:false,
        }
    }
})
Vue.component("show",{
    template:`
        <button @click="on_click()">显示余额</button>
        `,
    methods:{
        on_click(){
            console.log("caonidaye")
            this.$emit("show-balance")
        }
    }
})

new Vue({
    el:"#app"
})

 

组件-子父通信

标签:click   mit   body   set   lib   vue   lang   type   log   

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

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