1.因为在父组件页面是,已经创建了子组件,所以子组件挂载在monted的数据只会触发一次(父组件页面刷新的那一次);所以对我们之后操作子组件的信息就非常不舒服。
2.我们可以用watch进行监听数据,随后在更改子组件信息时重新调取接口就行。
props: ["lastDetails"],
watch: {
lastDetails: {
immediate: true, //立马监听
handler(newvalue, oldvalue) {
this.steps = this.lastDetails.children.length;
this.lastDetailsId = this.lastDetails.id;
this.rank = JSON.parse(localStorage.getItem("id")).role.rank;
this.userId = JSON.parse(localStorage.getItem("id")).id;
this.Activename = JSON.parse(localStorage.getItem("id")).name;
this.listData = this.lastDetails.newsinfo.pics;
this.childUser = this.lastDetails.children;
this.childbom();
},
},
},
3.批注完,立马调用接口,watch重新监听数据,进行渲染
// 领导确定批注
confirm() {
this.$api.leader_infos(this.leader).then((res) => {
if (res.message == "操作成功!") {
this.$toast.success({
message: "批注成功",
});
}
});
this.$api.Turn_NewsDetails(this.lastDetailsId).then((res) => {
this.lastDetails = res;
});
},