需求
android端和ios端點擊手機物理回傳鍵(左上角的)或頁面滑動鍵退出后,彈出彈框,點擊確定后才退出該頁面,
截圖展示:


實作代碼:
在onBackPress()方法中實作,
注意一定要在success后面加上.bind(this)代碼,不然ios端會出現,點擊物理回傳鍵后,先退出該頁面在出現彈框的問題,
親測有效(ios端和android端已測)
onBackPress() {
//console.log("press back");
uni.showModal({
title: '退出該頁面后將關閉此次軌跡記錄',
confirmText: '退出',
success: function(res) {
if (res.confirm) {
.....//此處把你退出后需要的方法寫上就行
this.stopGetLocation();
this.started = false;
this.imgpath = '../../static/open.png'
}
}.bind(this)//此處bind是關鍵
})
},
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/242908.html
標籤:其他
