Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
thinkApp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
游洁
thinkApp
Commits
2775c4fe
Commit
2775c4fe
authored
Jun 09, 2022
by
youjie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
4a34026e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
2 deletions
+60
-2
App.vue
src/App.vue
+60
-2
No files found.
src/App.vue
View file @
2775c4fe
<
script
>
export
default
{
onLaunch
()
{
// console.log('App Launch')
onLaunch
()
{
//调用定义的更新方法
this
.
VersionUpdate
();
},
onShow
()
{
// console.log('App Show')
...
...
@@ -12,6 +13,63 @@ export default {
onHide
()
{
// console.log('App Hide')
},
methods
:{
//定义更新方法
VersionUpdate
()
{
// 判断应用的 getUpdateManager 是否在当前版本可用
if
(
uni
.
canIUse
(
'getUpdateManager'
))
{
const
updateManager
=
uni
.
getUpdateManager
()
// 向小程序后台请求完新版本信息
updateManager
.
onCheckForUpdate
(
function
(
res
)
{
if
(
res
.
hasUpdate
)
{
//小程序有新版本,静默下载新版本,新版本下载完成
updateManager
.
onUpdateReady
(
function
()
{
//模态弹窗(确认、取消)
uni
.
showModal
({
title
:
'更新提示'
,
content
:
'小程序已发布新版本,是否重启?'
,
success
:
function
(
res
)
{
//用户点击确定
if
(
res
.
confirm
)
{
//当新版本下载完成,调用该方法会强制当前小程序应用上新版本并重启
updateManager
.
applyUpdate
()
}
//用户点击取消
else
if
(
res
.
cancel
)
{
//强制用户更新,弹出第二次弹窗
uni
.
showModal
({
title
:
'提示'
,
content
:
'小程序已发布新版本,是否重启'
,
showCancel
:
false
,
//隐藏取消按钮
success
:
function
(
res
)
{
//第二次提示后,强制更新
if
(
res
.
confirm
)
{
// 当新版本下载完成,调用该方法会强制当前小程序应用上新版本并重启
updateManager
.
applyUpdate
()
}
}
})
}
}
})
})
// 当新版本下载失败
updateManager
.
onUpdateFailed
(
function
()
{
uni
.
showModal
({
title
:
'提示'
,
content
:
'请您删除当前小程序,重新打开小程序'
,
})
})
}
})
}
else
{
// 提示用户在最新版本的客户端上体验
uni
.
showModal
({
title
:
'温馨提示'
,
content
:
'当前微信版本过低,可能无法使用该功能,请升级到最新版本后重试。'
})
}
}
}
};
</
script
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment