[Vuejs]-Async loaded data won't be rendered

0👍

Use a lambda instead of function to capture the context of this.

getProjectDataFromServer() {
      client.request('get', null, (err, response) => {
        if(err) throw err;
        this.data = response.result;
        this.loading = false;
        console.log(this.data);
      });
    }

Or capture the this context in a closure outside of the function.

getProjectDataFromServer() {
      const that = this;
      client.request('get', null, function (err, response) {
        if(err) throw err;
        that.data = response.result;
        that.loading = false;
        console.log(that.data);
      });
    }

Leave a comment