欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

uni-app小程序 onLaunch与onload异步请求的解决

程序员文章站 2022-07-03 10:10:40
...
onLaunch(){
	//异步请求
	this.sysParam().then(()=>{
		if(getApp().sysParamCallback){ //页面中定义的全局变量(函数)
			getApp().sysParamCallback();
		}
	}) 
}

onLoad(){
	if(getApp().globalData.xxx){ //存在全局变量
		this.getAppSysParam();
	}else{ //不存在全局变量
		getApp().sysParamCallback = res => {
			this.getAppSysParam();
		}
	}
}

getAppSysParam(type){
		//获取onLaunch中的全局变量逻辑代码
}