Skip to content

Commit 770957f

Browse files
committed
系统更新
1 parent 9b2e9ce commit 770957f

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

my-project-vue2/src/App.vue

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
11
<script>
2-
export default {
3-
onLaunch: function() {
4-
console.log('App Launch')
5-
},
6-
onShow: function() {
7-
console.log('App Show')
8-
},
9-
onHide: function() {
10-
console.log('App Hide')
2+
export default {
3+
onLaunch: function () {
4+
this.appUpdate()
5+
},
6+
onShow: function () {
7+
},
8+
onHide: function () {
9+
},
10+
methods: {
11+
// 系统更新
12+
appUpdate() {
13+
const updateManager = uni.getUpdateManager();
14+
updateManager.onCheckForUpdate(function (res) {
15+
// 请求完新版本信息的回调
16+
// console.log(res.hasUpdate);
17+
});
18+
updateManager.onUpdateReady(function (res) {
19+
uni.showModal({
20+
title: '更新提示',
21+
content: '新版本已经准备好,是否重启应用?',
22+
success(res) {
23+
if (res.confirm) {
24+
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
25+
updateManager.applyUpdate();
26+
}
27+
}
28+
});
29+
});
30+
updateManager.onUpdateFailed(function (res) {
31+
// 新的版本下载失败
32+
});
1133
}
1234
}
35+
}
1336
</script>
1437

1538
<style lang="scss">
16-
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
17-
@import "uview-ui/index.scss";
39+
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
40+
@import "uview-ui/index.scss";
1841
</style>

my-project-vue2/src/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ import httpApi from '@/api/http.api.js'
2626
Vue.use(httpApi, app)
2727

2828
app.$mount()
29+
30+

0 commit comments

Comments
 (0)