组件-子父通信
<!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" })
本文来自博客园,作者:一石数字欠我15w!!!,转载请注明原文链接:https://www.cnblogs.com/52-qq/p/8386304.html