哪里有网站建设商家,网站页面尺寸大小,费县网站建设,网站建设语言什么语言涉及到的知识点#xff1a;watch监控#xff1a;先看问题#xff0c;父组件从后端通过$ajax获取数据#xff0c;在将父组件将值传输给子组件#xff0c;使用子组件使用created钩子函数获取数据#xff0c;按自己的想法应该是父组件先获取后端数据#xff0c;在传入给子组…涉及到的知识点watch监控先看问题父组件从后端通过$ajax获取数据在将父组件将值传输给子组件使用子组件使用created钩子函数获取数据按自己的想法应该是父组件先获取后端数据在传入给子组件可是事实是子组件先获取数据父组件在从后端获取数据这样的话子组件就没有数据获取为空。
父页面: templateview classapproval-datailsview classinformation !--申请信息--uni-collapse refcollapse changechangeuni-collapse-item title审批流程 title-bordershow :opentrueuni-stepinformation :instanceApplyListinstanceApplyList/uni-stepinformation/uni-collapse-item/uni-collapse/view/view
/templatescriptexport default {data() {return {instanceApplyList:[],//传给子页面的数组}},methods: {getWaitingTask(){this.$ajax.getWaitingTask({id: this.id}, (response) {if (response.success true) {console.log(responseswaiting, response)this.result response.resultthis.instanceApplyList response.result.instanceApplyList// console.log(responseswaiting, this.result)console.log(this.instanceApplyList,this.instanceApplyList)}// this.listType(response)});},}}
/script
子页面 解决方法将子页面中钩子函数created变成watch监听当父页面获取到后端数据时再调用type函数方法这样就可以让父页面的函数先运行获取后端数据在吧数据传入子页面子页面获取数据在输出。 templateview classbox/view
/templatescriptexport default {props:{instanceApplyList: Array,default:() []},data() {return {judge:[],}},// created() {// this.type();// },watch:{instanceApplyList:{deep:true,handler(e){if(e.length0){this.type()}}}},methods: {type(){this.judgethis.instanceApplyListconsole.log(this.judge,this.judge) }}}
/script
运行结果