vue父组件传子组件数据不更新视图的方法
有时候需要父组件请求接口,然后把数据传递给子组件,页面渲染出来了,接口数据后面才返回出来,这样子组件就不是最新数据,导致页面数据显示错误。props: {file_list: {type: Array,default() {return []}}},data() {return {file_list_: this.file_list, // prop 位单向数据流,声明多一个
·
有时候需要父组件请求接口,然后把数据传递给子组件,页面渲染出来了,接口数据后面才返回出来,这样子组件就不是最新数据,导致页面数据显示错误。
props: {
list1: {
type: Array,
default() {
return []
}
}
},
data() {
return {
list2: this.list1, // prop 位单向数据流,声明多一个变量来存
}
},
watch: {
list1(newValue, oldValue) {
this.list2= newValue
}
},
更多推荐
已为社区贡献25条内容
所有评论(0)