(vue)父组件点击后子组件数据未及时更新
原因:
1.请求异步
2.子页面只有第一次加载时才走mounted(),所以数据为空。
方法:
用watch属性来监听数据动态变化
props: ["searchEngRes"], //父组件传的值
watch: {
searchEngRes(newVal, oldVal) {
this.searchEngRes = newVal;
newVal && this.dataShow();
newVal && this.tupuShow(); //图谱数据
},
},
methods:{
// 匹配数据
dataShow() {
this.shiTi = this.searchEngRes.data;
this.bufen = this.searchEngRes.relation;
...
},
}