uni-app uni.request同步操作逻辑

uni-app uni.request同步操作

uni-app uni.request同步操作逻辑_第1张图片
onload 中调用this.doTest()方法,会先执行 uni.request中打印的console.log(res),
再执行console.log(‘后打印’)

onLoad() {
			this.doTest();
		},
		methods: {
			async doTest(){
				await this.getTest();
				console.log('后打印'); 			  //后打印
			},
			getTest(){
				return new Promise((resolve,reject)=>{
					uni.request({
						url: 'https://......',
						method: 'POST',
						data: {},
						success: res => {
							console.log(res);     //先打印
							resolve('success');
						},
						fail: (err) => {
							console.log(err);
							reject('error');
						}
					})
				})
			}
		}

你可能感兴趣的:(uni-app,前端)