麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > JavaScript > 正文

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

2019-11-19 14:31:13
字體:
來源:轉載
供稿:網友

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

/** 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,會觸發子組件更新
  2. 父組件改變props,子組件如果將props放進data中再使用,不會觸發子組件更新
  3. 父組件改變props,子組件如果將props放進computed中再使用,會觸發子組件更新
  4. data,props和computed的變化都會觸發組件更新

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 99最新网址 | 在线免费小视频 | 国产成人精品午夜视频' | 天天夜天天操 | 日日鲁夜夜视频热线播放 | 亚洲第一页视频 | 好吊色欧美一区二区三区四区 | 久久狠狠高潮亚洲精品 | 中文字幕免费播放 | 久久久av亚洲男天堂 | 欧美成人精品欧美一级乱黄 | 一本色道久久99精品综合蜜臀 | 草碰人人| 久久噜噜噜精品国产亚洲综合 | 欧美日韩国产成人在线观看 | 国产精品刺激对白麻豆99 | 视频一区二区三区视频 | 成人免费观看49www在线观看 | 深夜影院一级毛片 | 亚洲午夜久久久久 | 性欧美一区 | 午夜国内精品a一区二区桃色 | 久久精品一二三区白丝高潮 | 毛片a片| 欧美精品久久久久久久多人混战 | 久久综合一区二区 | 中国女警察一级毛片视频 | 黄色网电影 | 成人免费毛片片v | 欧美一级黄色免费看 | 国产精品久久久久久久成人午夜 | 九九热视频这里只有精品 | 禁漫天堂久久久久久久久久 | 欧美成人激情在线 | 日本黄色免费观看视频 | 精品一区二区亚洲 | 99视频在线观看视频 | 九九精品在线播放 | 激情亚洲一区二区三区 | 国产精品热| 男人的天堂毛片 |