uni-app捣鼓之路---------request同步解决

uni-app本身就是异步的操作,不存在async参数配置快速修改,如要变成同步可加async+wait将request变成同步

onLoad() {
	this.doLoad();
	},
methods:{
			
    async doLoad(){
        let cc =  await this.getLoad();
	    console.log(cc )
	},
    getLoad: function(){
        return new Promise(resolve => {
			uni.request({
				header:{"content-type":"application/x-www-form-urlencoded"},
				url: "",
				method: "POST",
				data: {},
				success(res) {
					resolve(res.data.data)
							
				},
				fail(res) {
					console.log(res)
				}
					})
	}).catch((e) => {});
	}
}
posted @ 2020-02-11 17:22  孙振光  阅读(1195)  评论(0)    收藏  举报