uni.app如何检测小程序版本更新以及上线后如何关闭全局打印

uni.app如何检测小程序版本更新以及上线后如何关闭全局打印

检测小程序版本更新

App.vue 入口文件中 添加如下代码

	//检测小程序版本是否更新
	const updateManager = wx.getUpdateManager()
	updateManager.onCheckForUpdate(function(res) {
    
    
		// 请求完新版本信息的回调
		console.log(res)
	})
	//更新版本
	updateManager.onUpdateReady(function() {
    
    
		wx.showModal({
    
    
			title: '更新提示',
			content: '新版本已经准备好,是否重启应用?',
			success(res) {
    
    
				if (res.confirm) {
    
    
					// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
					updateManager.applyUpdate()
				}
			}
		})
	})
	updateManager.onUpdateFailed(function () {
    
    
	  // 新版本下载失败
	})
	uni.getStorageSync('')

  • 微信小程序 测试
    在这里插入图片描述
  • 重新编译后 即可看到以下内容
    在这里插入图片描述

关闭全局打印

在main.js中 加上以下代码

// 上线后全局关闭console.log打印
if (uni.getSystemInfoSync().platform !== "devtools") {
    
    
	console.log = () => {
    
    };
	console.info= () => {
    
    };
}

猜你喜欢

转载自blog.csdn.net/Gik99/article/details/131815062