1***@163.com
1***@163.com
  • 发布:2018-12-21 15:45
  • 更新:2018-12-28 19:28
  • 阅读:2342

怎么把接口请求回来的数据同步到data,我用的官方Promise写法。求大神指点。。。

分类:uni-app

data() {
return {
classdata:""
}
}
created() {
this.getdata()
console.log(this.classdata)//这里打印是空的
},
methods: {
getdata: async function () {
let CLASS = {}
CLASS.token = this.user.token
CLASS.orgid = this.user.id
CLASS.class = this.workData.clsid
let err,res;
[err,res] = await uni.request({
method: 'POST',
url: this.Url+'/getclass',
data: CLASS
});
this.classdata = res.data
console.log(this.classdata)//这里确有内容
console.log(res);
}
}

2018-12-21 15:45 负责人:无 分享
已邀请:
虫雪浓

虫雪浓 - 热爱生活,热爱编程

你在 created 的钩子中 直接 调用 this.getdata(); 其实也是异步操作,所以你拿不到值。 如果你也想拿到 ,那么也得用async -await。

1***@qq.com

1***@qq.com

表示用的this._data.参数名

该问题目前已经被锁定, 无法添加新回复