關(guān)于父子組件之間傳遞數(shù)據(jù)其實(shí)文檔上都說得很明白。
但是如果完全不懂的人做計(jì)也看不懂,下面是一個(gè)小例子,有兩個(gè)文件
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)聽此事件的回調(diào)函數(shù)的值設(shè)為200 this.$emit('ok','200'); }}</script><!-- Add "scoped" attribute to limit CSS to this component only --><style scoped></style>總結(jié)
以上所述是小編給大家介紹的vue2.0父子組件間傳遞數(shù)據(jù)的方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)武林網(wǎng)網(wǎng)站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注