vue中页面向后台请求数据,返回的数据在请求方法中赋值给data中的属性,结果在请求方法外输出data数据显示未能成功赋值,请求方法内的赋值没有形成全局效果,仅在方法内输出可见结果。这是为什么?用var that = this 转过,仍然无效
```async bigBranch2() {
var that = this;
this.branches2 = await branchData2(reported);
console.log(this.branches2);//有东西
that.xAxis = toRaw(this.branches2).data.data;
that.series = toRaw(this.branches2).data.series;
console.log(that.xAxis, that.series); //有东西
console.log(toRaw(this.branches2).data.series); //有东西
console.log(toRaw(this.branches2).data.data); //有东西
}
```created() {
this.bigBranch2();//请求方法
console.log(this.xAxis, this.series); //没有东西
console.log(toRaw(this.series)); //没有东西
},
this.bigBranch2();//请求方法 改为 await this.bigBranch2();
异步
var that = this ,要写在函数外面叭,写在函数里面this就指向该函数了
created(){
this.bigBranch2();//请求方法
this.$nextTick(function(){
console.log(this.xAxis, this.series);
console.log(toRaw(this.series));
})
}