添加小程序更新代码

This commit is contained in:
chenhaizhao 2025-12-29 15:46:30 +08:00
parent 1c85a641e4
commit 6ed45b630f

39
App.vue
View File

@ -1,15 +1,34 @@
<script>
export default {
onLaunch: function() {
console.log('App Launch')
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
<script setup>
import { onLaunch } from "@dcloudio/uni-app"
onLaunch(() => {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
//
console.log(res.hasUpdate)
})
updateManager.onUpdateReady(function () {
uni.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success(res) {
if (res.confirm) {
// applyUpdate
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
//
uni.showToast({
title: '更新失败,请手动清理缓存重试',
icon: 'none'
});
})
})
</script>
<style>