我们经常可以看到一些小程序更新一个版本之后,我们再次打开会收到版本更新提示,这是这么做到的呢?以下以wepy为例,我们可以在:项目\src\app.wpy文件下加入以下更新提示代码:wepy.app({; ; async onLaunch() {
我们经常可以看到一些小程序更新一个版本之后,我们再次打开会收到版本更新提示,这是这么做到的呢?以下以wepy为例,我们可以在:项目\src\app.wpy文件下加入以下更新提示代码:
wepy.app({
async onLaunch() {
console.log('热更新')
if (wx.canIUse("getUpdateManager")) {
const updateManager = wx.getUpdateManager();
updateManager.onCheckForUpdate(function(res) {
console.log("onCheckForUpdate====11111", res);
// 请求完新版本信息的回调
if (res.hasUpdate) {
console.log("res.hasUpdate====");
}
});
updateManager.onUpdateReady(function(res) {
console.log(111, res);
wx.showModal({
title: "版本更新",
content: "新版本已经准备好,确定重启应用?",
showCancel: false,
success: function(res) {
console.log("success====", res);
// res: {errMsg: "showModal: ok", cancel: false, confirm: true}
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate();
}
}
});
});
updateManager.onUpdateFailed(function() {
// 新的版本下载失败
wx.showModal({
title: "已经有新版本了哟~",
content: "新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~"
});
});
}
},
methods: {
},
globalData: {
}
})
这样我们若是提交新的版本之后,上线,用不打开就会提示版本更新,需要重新进入。
编程基础网
本文标题为:wepy微信小程序框架加入版本更新提示
基础教程推荐
猜你喜欢
- AJAX实现数据的增删改查操作详解【java后台】 2023-02-23
- ajax异步加载图片实例分析 2022-12-18
- JavaScript开发简单易懂的Svelte实现原理详解 2023-08-12
- 【vue】三种获取input值的写法 2023-10-08
- html网页中使用希腊字母的方法 2022-09-21
- Ajax实现关键字联想和自动补全功能及遇到坑 2023-02-23
- 使用HTML5中postMessage知识点解决Ajax中POST跨域问题 2022-10-17
- vue在install时node-sass@4.14.1 postinstall:node scripts/build.js错误解决 2023-07-09
- Ajax实现简单下拉选项效果【推荐】 2022-12-28
- JavaScript函数this指向问题详解 2023-08-12
