怎么在Vue2.0中實現(xiàn)組件間的數(shù)據(jù)傳遞

這期內(nèi)容當(dāng)中小編將會給大家?guī)碛嘘P(guān)怎么在Vue2.0中實現(xiàn)組件間的數(shù)據(jù)傳遞,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

為珠山等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及珠山網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為網(wǎng)站制作、成都網(wǎng)站設(shè)計、珠山網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!

1,父組件向子組件傳遞場景:Father上一個輸入框,根據(jù)輸入傳遞到Child組件上。

父組件:

<template>
 <div>
  <input type="text" v-model="msg">
  <br>
  //將子控件屬性inputValue與父組件msg屬性綁定
  <child :inputValue="msg"></child>
 </div>
</template>
<style>

</style>
<script>
 export default{
  data(){
   return {
    msg: '請輸入'
   }
  },
  components: {
   child: require('./Child.vue')
  }
 }
</script>

子組件:

<template>
 <div>
  <p>{{inputValue}}</p>
 </div>
</template>
<style>

</style>
<script>
  export default{
    props: {
     inputValue: String
    }
  }
</script>

2,子組件向父組件傳值場景:子組件上輸入框,輸入值改變后父組件監(jiān)聽到,彈出彈框

 父組件:

<template>
 <div>
//message為子控件上綁定的通知;recieveMessage為父組件監(jiān)聽到后的方法
  <child2 v-on:message="recieveMessage"></child2>
 </div>
</template>
<script>
 import {Toast} from 'mint-ui'
 export default{
  components: {
   child2: require('./Child2.vue'),
   Toast
  },
  methods: {
   recieveMessage: function (text) {
    Toast('監(jiān)聽到子組件變化'+text);
   }
  }
 }
</script>

子組件:

<template>
 <div>
  <input type="text" v-model="msg" @change="onInput">
 </div>
</template>
<script>
 export default{
  data(){
   return {
    msg: '請輸入值'
   }
  },
  methods: {
   onInput: function () {
    if (this.msg.trim()) {
     this.$emit('message', this.msg);
    }
   }
  }
 }
</script>

上述就是小編為大家分享的怎么在Vue2.0中實現(xiàn)組件間的數(shù)據(jù)傳遞了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

文章標(biāo)題:怎么在Vue2.0中實現(xiàn)組件間的數(shù)據(jù)傳遞
分享網(wǎng)址:http://muchs.cn/article48/ispiep.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計公司、移動網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、用戶體驗、小程序開發(fā)、面包屑導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化