原创: 调用async请求有返回值函数,接收传值不成功问题

 

 如下是如上代码,无法接收返回参数:

 onLoad(){
const aa = await this.getRadioExams();
console.log("aa的值", aa)

}

 正确写法如下两种

添加 async ,本人测试成功

data() {
            return {
                radioList: []
            }
        },
        onLoad() {
           let _this = this;
            this.getRadioExams().then(data => {
                console.log("返回请求的值为:", data);
                _this.radioList = data.rows;
            })
            
        },

或者解决方案二

//添加 async ,本人测试成功	
async onLoad() { let _this = this; _this.radioList=await this.getRadioExams(); },

 

posted @ 2022-06-09 22:22  码哥之旅  阅读(413)  评论(0编辑  收藏  举报