uniapp异步方法让同步执行 await async

	onShow() {				
		this.grantShare();
	},
	methods: {
		grantShare(){ //授权判断
			let that = this;
			return new Promise((resolve, reject) => {
				$api.ajax({
					url:"/Share/check_user_relation_id",
					data:{},
					method: "POST",
					success:(res)=>{
						if(res.code == 0){ //已授权
							this.grantState = false;
							this.layerGrantShow = false;
						}else{ 
							// that.grantState = true;									
						}		
						resolve('suc');				
					},
					error(msg){
						uni.showModal({
							title:'提示',
							content:"请检查网络或者重新登录"
						})	
						this.grantState = true;
						reject('msg');
					}
				});	
			})
		},
		async mountDealCount(){
			await this.grantShare();	
			await $user.userLogin();//执行grantShare成功之后的方法
			
		},
	},
	beforeMount(){
		this.mountDealCount()
	}
Logo

鸿蒙生态一站式服务平台。

更多推荐