国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

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

2024-05-06 15:22:38
字體:
來源:轉載
供稿:網友

本文介紹了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>             
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 新沂市| 江陵县| 镇雄县| 拉孜县| 梁河县| 交口县| 南安市| 杂多县| 安远县| 光山县| 黎城县| 县级市| 茶陵县| 利辛县| 石棉县| 九台市| 河北区| 威信县| 遂溪县| 扶余县| 平南县| 余江县| 松溪县| 永昌县| 琼结县| 磐石市| 盘山县| 怀来县| 宣武区| 遂溪县| 辽宁省| 贵港市| 永吉县| 邯郸市| 盖州市| 大城县| 临澧县| 华安县| 民和| 从化市| 新和县|