vue2.0父子組件間傳遞數據的方法
更新時間:2018年08月16日 09:59:06 作者:5649498
本文通過一個小例子給大家介紹了vue2.0父子組件間傳遞數據的方法,需要的朋友參考下吧
關于父子組件之間傳遞數據其實文檔上都說得很明白。
但是如果完全不懂的人做計也看不懂,下面是一個小例子,有兩個文件
1.parent.vue
<template> <child :child-msg="msg" @ok="event"></child> </template> <script> import child from './child.vue'; export default { data(){ return{ msg:'hello worldgogo' } }, components:{ child }, methods:{ event(val){ console.log(val); } } } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> </style>
2.child.vue
<template> <p>{{childMsghello}}</p> </template> <script> export default { props: ['childMsg'], data(){ return{ childMsghello:this.childMsg+'this is child' } }, created(){ //自定義事件,并且給監(jiān)聽此事件的回調函數的值設為200 this.$emit('ok','200'); } } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> </style>
總結
以上所述是小編給大家介紹的vue2.0父子組件間傳遞數據的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
相關文章
關于vue-admin-element中的動態(tài)加載路由
這篇文章主要介紹了關于vue-admin-element的動態(tài)加載路由,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08Vue實現調節(jié)窗口大小時觸發(fā)事件動態(tài)調節(jié)更新組件尺寸的方法
今天小編就為大家分享一篇Vue實現調節(jié)窗口大小時觸發(fā)事件動態(tài)調節(jié)更新組件尺寸的方法。具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09