直接上代码
<view v-if="isShow">
<page-container :show="isShow" :overlay="false" @beforeleave="beforeleave"></page-container>
</view>
页面引入
data(){
return isShow:true
}
状态
beforeleave() {
this.isShow = false; //这个很重要,一定要先把弹框删除掉
uni.showModal({
title: '提示',
content: '当前操作未完成,确认要放弃吗?',
success: res => {
if (res.confirm) {
console.log('用户点击确认')
//清理本地缓存
uni.clearStorageSync()
//跳转用户页面
uni.reLaunch({
url: '/pages/user/user'
})
} else {
console.log('用户点击取消')
this.isShow = true; // 关键代码:重新显示容器
this.resetProcessStatus();
}
},
complete: () => {
// 无论选择确认/取消都需要:
this.isShow = true; // 防止容器自动关闭
}
})
},
方法