Undefined error is reported when vue listens for array changes

when vue listens for array changes and assigns values to oldArray, oldArray prompts undefined

in the watch method, deep monitoring is used to listen for changes in newArray, and changes can be detected, but when assigning the changed value to oldArray, it prompts undefined

        data (){
            return {
                downloadUrl: (function () {
                    return "http://" + document.domain + ":38010"
                })(),
                oldImgs: this.$route.query.contractInfo,
                rowkey: this.$route.query.rowkey,
                copyLocalIds: [],
                newImgs:[],
                transLocalIds:[]
            }
        },
        created (){
            if (this.oldImgs && this.oldImgs.length > 0) {
                this.oldImgs = this.oldImgs.split(";");
                if (this.oldImgs[this.oldImgs.length-1] == "") {
                    this.oldImgs.pop();//
                }
                for (var i = 0; i < this.oldImgs.length; iPP) {
                    this.oldImgs[i] = this.downloadUrl+"/contractInfo"+this.oldImgs[i];
                }
            }
        },
        watch :{
            "newImgs":{
                deep: true,
                handler: (val,oldVal)=>{
                    console.log(":"+this.oldImgs);
                    if (this.oldImgs.length>0) {
                        this.oldImgs = this.oldImgs.concat(val);
                    } else {
                        this.oldImgs = val;
                    }
                    
                }
            }
        },
Apr.09,2021

suspected that the arrow function caused the this to be lost. Try using function instead.

Menu