最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

淺談vue的props,data,computed變化對(duì)組件更新的影響

 更新時(shí)間:2018年01月16日 09:50:56   作者:waiting_h  
本篇文章主要介紹了淺談vue的props,data,computed變化對(duì)組件更新的影響,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

本文介紹了vue的props,data,computed變化對(duì)組件更新的影響,分享給大家,廢話不多說(shuō),直接上代碼

/** this is Parent.vue */
<template>
 <div>
  <div>{{'parent data : ' + parentData}}</div>
  <div>{{'parent to children1 props : ' + parentToChildren1Props}}</div>
  <div>{{'parent to children2 props : ' + parentToChildren2Props}}</div>
  <div>
   <el-button @click="changeParentData">change parent data</el-button>
   <el-button @click="changeParentToChildren1Props">change parent to children1 data</el-button>
   <el-button @click="changeParentToChildren2Props">change parent to children2 data</el-button>
  </div>
  <my-children1 :children1Props="parentToChildren1Props" @changeParentToChildren1Props="changeParentToChildren1Props"></my-children1>
  <my-children2 :children2Props="parentToChildren2Props" @changeParentToChildren2Props="changeParentToChildren2Props"></my-children2>
 </div>
</template>

<script>
 import Children1 from './Children1';
 import Children2 from './Children2';
 export default{
  name: 'parent',
  data() {
   return {
    parentData: 'ParentData',
    parentToChildren1Props: 'ParentToChildren1Props',
    parentToChildren2Props: 'ParentToChildren2Props'
   }

  },

  beforeCreate: function() {
   console.log('*******this is parent beforeCreate*********');

  },

  created: function() {
   console.log('######this is parent created######');

  },

  beforeMount: function() {
   console.log('------this is parent beforeMount------');

  },

  mounted: function() {
   console.log('++++++this is parent mounted++++++++');

  },

  beforeUpdate: function() {
   console.log('&&&&&&&&this is parent beforeUpdate&&&&&&&&');

  },

  updated: function() {
   console.log('$$$$$$$this is parent updated$$$$$$$$');

  },

  methods: {
   changeParentData: function() {
    this.parentData = 'changeParentData'

   },

   changeParentToChildren1Props: function() {
    this.parentToChildren1Props = 'changeParentToChildren1Props'

   },

   changeParentToChildren2Props: function() {
    this.parentToChildren2Props = 'changeParentToChildren2Props'

   }

  },
  components: {
   'my-children1': Children1,
   'my-children2': Children2
  }
 }
</script> 

/** this is Children1.vue */
<template>
 <div>
  <div>{{'children1 data : ' + children1Data}}</div>
  <div>{{'parent to children1 props : ' + children1Props}}</div>
  <div>{{'parent to children1 props to data : ' + children1PropsData}}</div>
  <div>
   <el-button @click.native="changeChildren1Data">change children1 data</el-button>
   <el-button @click.native="emitParentToChangeChildren1Props">emit parent to change children1 props</el-button>
  </div>
 </div>
</template>

<script>
 export default {
  name: 'children1',
  props: ['children1Props'],
  data() {
   return {
    children1Data: 'Children1Data'
   }
  },

  computed: {
   children1PropsData: function() {
    return this.children1Props
   }
  },

  beforeCreate: function() {
   console.log('*******this is children1 beforeCreate*********');

  },

  created: function() {

   console.log('######this is children1 created######');
  },

  beforeMount: function() {
   console.log('------this is children1 beforeMount------');

  },

  mounted: function() {
   console.log('++++++this is children1 mounted++++++++');

  },

  beforeUpdate: function() {
   console.log('&&&&&&&&this is children1 beforeUpdate&&&&&&&&');

  },

  updated: function() {
   console.log('$$$$$$$this is children1 updated$$$$$$$$');

  },

  methods: {
   changeChildren1Data: function() {
    this.children1Data = 'changeChildren1Data'

   },

   emitParentToChangeChildren1Props: function() {
    console.log('emitParentToChangeChildren1Props');
    this.$emit('changeParentToChildren1Props');
   }
  }
 }
</script> 

/** this is Children2.vue */
<template>
 <div>
  <div>{{'children2 data : ' + children2Data}}</div>
  <div>{{'parent to children2 props : ' + children2Props}}</div>
  <div>{{'parent to children2 props to data : ' + children2PropsData}}</div>
  <div>
   <el-button @click.native="changeChildren2Data">change children2 data</el-button>
   <el-button @click.native="emitParentToChangeChildren2Props">emit parent to change children2 props</el-button>
  </div>
 </div>
</template>

<script>
 export default {
  name: 'children2',
  props: ['children2Props'],
  data() {
   return {
    children2Data: 'Children2Data',
    children2PropsData: this.children2Props
   }
  },

  beforeCreate: function() {
   console.log('*******this is children2 beforeCreate*********');

  },

  created: function() {
   console.log('######this is children2 created######');

  },

  beforeMount: function() {
   console.log('------this is children2 beforeMount------');

  },

  mounted: function() {
   console.log('++++++this is children2 mounted++++++++');

  },

  beforeUpdate: function() {
   console.log('&&&&&&&&this is children2 beforeUpdate&&&&&&&&');

  },
  updated: function() {
   console.log('$$$$$$$this is children2 updated$$$$$$$$');

  },

  methods: {
   changeChildren2Data: function() {
    this.children2Data = 'changeChildren2Data'
   },

   emitParentToChangeChildren2Props: function() {
    this.$emit('changeParentToChildren2Props');
   }
  }
 }
</script> 
  1. 父組件改變props,子組件如果直接使用props,會(huì)觸發(fā)子組件更新
  2. 父組件改變props,子組件如果將props放進(jìn)data中再使用,不會(huì)觸發(fā)子組件更新
  3. 父組件改變props,子組件如果將props放進(jìn)computed中再使用,會(huì)觸發(fā)子組件更新
  4. data,props和computed的變化都會(huì)觸發(fā)組件更新

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 如何使用Webpack優(yōu)化Vue項(xiàng)目的打包流程

    如何使用Webpack優(yōu)化Vue項(xiàng)目的打包流程

    在開(kāi)發(fā)基于Vue.js的應(yīng)用時(shí),隨著項(xiàng)目規(guī)模的擴(kuò)大,單個(gè)文件的體積也會(huì)隨之增長(zhǎng),特別是當(dāng)涉及到大量的依賴庫(kù)和復(fù)雜的業(yè)務(wù)邏輯時(shí),本文將詳細(xì)介紹如何使用Webpack來(lái)優(yōu)化Vue項(xiàng)目的打包流程,需要的朋友可以參考下
    2024-09-09
  • 關(guān)于vue-treeselect綁值、回顯等常見(jiàn)問(wèn)題的總結(jié)

    關(guān)于vue-treeselect綁值、回顯等常見(jiàn)問(wèn)題的總結(jié)

    這篇文章主要介紹了關(guān)于vue-treeselect綁值、回顯等常見(jiàn)問(wèn)題的總結(jié),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-07-07
  • vue 項(xiàng)目代碼拆分的方案

    vue 項(xiàng)目代碼拆分的方案

    這篇文章主要介紹了vue 項(xiàng)目代碼拆分的方案,幫助大家更好的理解和學(xué)習(xí)使用vue框架,感興趣的朋友可以了解下
    2021-03-03
  • 詳解如何創(chuàng)建并發(fā)布一個(gè) vue 組件

    詳解如何創(chuàng)建并發(fā)布一個(gè) vue 組件

    這篇文章主要介紹了詳解如何創(chuàng)建并發(fā)布一個(gè)vue組件,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-11-11
  • vue3鼠標(biāo)經(jīng)過(guò)顯示按鈕功能的實(shí)現(xiàn)

    vue3鼠標(biāo)經(jīng)過(guò)顯示按鈕功能的實(shí)現(xiàn)

    本篇文章介紹了如何使用 Vue3 實(shí)現(xiàn)一個(gè)鼠標(biāo)經(jīng)過(guò)顯示按鈕的效果,我們使用了 Vue3 的 Composition API 來(lái)創(chuàng)建響應(yīng)式的數(shù)據(jù),并使用了?@mouseover?和?@mouseleave?事件來(lái)監(jiān)聽(tīng)鼠標(biāo)的移入和移出事件,感興趣的朋友一起看看吧
    2024-04-04
  • element-ui自定義表格如何給input雙向綁定數(shù)據(jù)

    element-ui自定義表格如何給input雙向綁定數(shù)據(jù)

    這篇文章主要介紹了element-ui自定義表格如何給input雙向綁定數(shù)據(jù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • vue可視化大屏實(shí)現(xiàn)無(wú)線滾動(dòng)列表飛入效果

    vue可視化大屏實(shí)現(xiàn)無(wú)線滾動(dòng)列表飛入效果

    本文主要介紹了vue可視化大屏實(shí)現(xiàn)無(wú)線滾動(dòng)列表飛入效果,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04
  • vue內(nèi)點(diǎn)擊url下載文件的最佳解決方案分享

    vue內(nèi)點(diǎn)擊url下載文件的最佳解決方案分享

    這篇文章主要給大家介紹了關(guān)于vue內(nèi)點(diǎn)擊url下載文件的最佳解決方案,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2022-02-02
  • vue日期時(shí)間工具類詳解

    vue日期時(shí)間工具類詳解

    這篇文章主要為大家詳細(xì)介紹了vue日期時(shí)間工具類,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • vue基于element的區(qū)間選擇組件

    vue基于element的區(qū)間選擇組件

    這篇文章主要介紹了vue基于element的區(qū)間選擇組件,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-09-09

最新評(píng)論

边坝县| 山丹县| 天津市| 平定县| 铜山县| 文登市| 华池县| 嵊泗县| 孟州市| 澳门| 荣昌县| 彰化县| 宜春市| 平原县| 涟源市| 横峰县| 延寿县| 孟村| 长顺县| 开平市| 九江市| 蛟河市| 紫云| 巴塘县| 惠安县| 土默特左旗| 十堰市| 鸡东县| 台东县| 广饶县| 麻阳| 上思县| 湖南省| 墨江| 阳朔县| 建德市| 彝良县| 梨树县| 荥阳市| 苏尼特左旗| 稻城县|