欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue2.0父子組件間傳遞數(shù)據(jù)的方法

 更新時間:2018年08月16日 09:59:06   作者:5649498  
本文通過一個小例子給大家介紹了vue2.0父子組件間傳遞數(shù)據(jù)的方法,需要的朋友參考下吧

關(guān)于父子組件之間傳遞數(shù)據(jù)其實(shí)文檔上都說得很明白。

 但是如果完全不懂的人做計(jì)也看不懂,下面是一個小例子,有兩個文件

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ù)的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論