因为mounted函数只会在html和模板渲染之后会加载一次,但是在子组件中只有第一次的数据显示是正常的,所以需要再增加一个updated函数,在更新之后就可以重新进行取值加载,完成数据的正常显示。
beforCreate(创建之前)
Created(创建之后)
beforMount(载入之前)
Mounted(载入之后)
beforUpdate(更新之前)
Updated(更新之后)
beforDestroy(销毁之前)
Destroyed(销毁之后)
activate(keep-alive组件激活时调用)
deactivated(keep-alive组件停用时调用)
errorCaptured(这个组件的作用是接受子孙组件报错是调用,三个参数 错误对象、错误的组件、错误信息)
父组件向
子组件传值
通过父组件传值调用子组件显示不同的数据
父组件 :conponent.vue
子组件:iconponent.vue
父组件
<template> <div> <span>父组件</span> <icomponent-box :id="this.id"></icomponent-box> </div> </template> <script> //导入子组件 import icomponent from './icomponent.vue'; export default { data () { return { id:12 } }, components:{ //用来注册子组件的节点 "icomponent-box": icomponent } } </script> <style> </style>
子组件
<template> <div>子组件</div> </template> <script> export default { updated:{ this.getComponents(); }, mounted:{ this.getComponents(); }, data () { return { } }, methods:{ getComponents(){ this.$http.get("api/getcomponents/" + this.id); } }, props: ["id"] //接收父组件传递过来的id值 } </script>
补充知识:Vue父子组件传值,子组件数据只更新一次,之后更改父组件的数据,子组件不再更新
我就废话不多说了,大家还是直接看代码吧~
props:{ reportInfo:{ type:Object, default:()=>{} } }, data:function(){ return { cityName :' ', reportId :' ' , } } mounted:function () { var _this = this; //初始化获得数据,之后在watch中监听更新 _this.cityName = _this.reportInfo.cityName; _this.reportId = _this.reportInfo.reportId; }, watch:{ reportInfo(newValue, oldValue) { var _this = this; _this.cityName = newValue.cityName; _this.reportId = newValue.reportId; } }
以上这篇vue中父子组件传值,解决钩子函数mounted只运行一次的操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 杨千嬅.2002-万紫千红演唱会2CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郭采洁.2015-Begin.Again爱造飞鸡【华纳】【FLAC分轨】
- 许志安.2011-ON.AND.ON【东亚】【WAV+CUE】
- 潘秀琼.1994-木兰从军【名将】【WAV+CUE】
- 纯音入心系列纯音乐《古筝系列-当流行乐遇到古筝》1CD[MP3][1.9GB]
- 纯音入心系列纯音乐《精选古筝名曲100首》1CD[MP3][388.7MB]
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]
- TrioZimbalist-PianoTriosofWeinberg,Auerbach,Dvorak(2024)[24-44,1]wav
- 群星.1992-滚石第一流台湾歌·12王牌大车拼【滚石】【WAV+CUE】
- 林子祥.1984-创作歌集【华纳】【WAV+CUE】
- 周汤豪.2010-周汤豪【华纳】【FLAC分轨】
- Mozart-TheStringQuintets-AmadeusQuartet,CecilAronowitz(2017)[24-44,1][WAV+CUE]
- JamesWilliamsDennisIrwin-Focus(2024,Red)[24-48]FLAC