wkswang 2022-08-19 14:59 采纳率: 0%
浏览 75

vue后台返回数据赋值data属性失败

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));        //没有东西

},

  • 写回答

4条回答 默认 最新

  • 向上的时钟塔 2022-08-19 15:04
    关注

    this.bigBranch2();//请求方法 改为 await this.bigBranch2();

    评论

报告相同问题?

问题事件

  • 创建了问题 8月19日

悬赏问题

  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 数学建模数学建模需要
  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥20 nao机器人语音识别问题
  • ¥15 怎么生成确定数目的泊松点过程
  • ¥15 layui数据表格多次重载的数据覆盖问题
  • ¥15 python点云生成mesh精度不够怎么办
  • ¥15 QT C++ 鼠标键盘通信