早睡早起,方能养生
Sleep early rise early, way to keep healthy

uniapp微信小程序更新(新版本下载)提示

super
2021-11-05 20:52
views 2368

在App.vue中新增以下代码:

 

onLaunch

 

onLaunch: function(e) {
	let scene = e.scene; // 获取微信小程序场景值

	if (scene !== 1154) {
		const updateManager = wx.getUpdateManager();
		updateManager.onCheckForUpdate(function (res) {
			// 请求完新版本信息的回调
			if (res.hasUpdate) {
				updateManager.onUpdateReady(function () {
					wx.showModal({
						title: '更新提示',
						content: '新版本已经准备好,是否重启应用?',
						success: function (res) {
							if (res.confirm) {
								// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
								updateManager.applyUpdate();
							}
						}
					})
				}),
				updateManager.onUpdateFailed(function () {
					wx.showModal({
						title: '已经有新版本了哟~',
						content: '新版本已经上线啦~,请您删除小程序后,重新搜索(无敌百宝箱)小程序打开哟~',
						showCancel:false
					})
				})
			}
		})
	}
}

 

Q:场景值1154是什么?

A:场景值1154为微信朋友圈分享进入

 

Q:为什么要添加1154判断?

A:因为微信小程序朋友圈分享进入,在小程序预览单页中,更新函数会提示报错

 

tip: 请将括号中的小程序名称换成你的小程序的名称

 

欢迎访问我的小程序


分享
0 条讨论
top