The problem of method call encapsulated by methods in Vue

The

problem, as noted below, is simply that I called another method in a method in methods, but the method I called did not successfully manipulate the value in my data. I passed the value in this data as a parameter.

 data(){
    return {
        loadList:[]
    }
 },
 methods: {
    //loadingGet
    loadingGet:function(loaddata,resdata,loadnum){
        if(loaddata.length + loadnum > resdata.length){
              loaddata = resdata.slice(0,resdata.length);
                
              if(loaddata.length == resdata.length){
                this.loading = false;
                this.finished = true;
              }else {
                this.finished = false;
              }
            }else{
                loaddata = resdata.slice(0,loaddata.length + loadnum)
                this.loading = false;
                
                console.log(loaddata)//
                console.log(this.loadList)//undefined
            }

    },
    onLoad(){
      this.loading = true;
      axios.get("https://XXX")
      .then(res=>{
        console.log(res.data);
        let goods = res.data;
        if(this.tabIndex == 0){
          this.loadingGet(this.loadList,goods,6);//
          console.log(this.loadList)//
        }
         
      });
      
    },
  },
The methods in

vue methods cannot use the arrow function because the arrow function itself does not have this , which is why your console.log (this.loadList) is undefined


I don't seem to see your assignment

loadingGet: function(loaddata,resdata,loadnum) {
    // 
    // 
    return loaddata
}
onLoad () {
    this.loadList = this.loadingGet(this.loadList,goods,6);//
}

loaddata = resdata.slice(0,loaddata.length + loadnum)
this.loading = false;
this.loadList = loaddata;//****
console.log(loaddata)
console.log(this.loadList)

you are right upstairs, there is no assignment to this.loadList


you use the arrow function to change the this direction. If you don't point to the vue instance, it's impossible to change it to data, methods, and so on

.
Menu