有时候需要父组件请求接口,然后把数据传递给子组件,页面渲染出来了,接口数据后面才返回出来,这样子组件就不是最新数据,导致页面数据显示错误。

props: {
    list1: {
        type: Array,
        default() {
            return []
        }
    }
},
data() {
    return {
        list2: this.list1, // prop 位单向数据流,声明多一个变量来存
    }
},
watch: {
        list1(newValue, oldValue) {
            this.list2= newValue
        }
    },
Logo

前往低代码交流专区

更多推荐