uni-app页面返回事件监听处理
系统默认返回事件可以执行返回上一页操作,不需要特意去监听事件,如果需要在返回事件是执行操作,需要对返回事件进行监听处理,监听事件为onBackPress
页面返回事件监听处理
特别说明:微信小程序不支持返回页面监听
返回事件默认操作
系统默认返回事件可以执行返回上一页操作,不需要特意去监听事件,如果需要在返回事件是执行操作,需要对返回事件进行监听处理,监听事件为onBackPress,示例如下
export default {
onBackPress(options) {
console.log(options)
//页面点击返回事件
if (options.from === 'navigateBack') {
//doing
}
},
methods: {
back() {},
}
};
返回事件中断操作
在onBackPress事件中执行return false;是不能中断默认返回上一页事件的,如果需要中断默认事件需要执行return true操作
export default {
data() {
return {
showMask: true,
};
},
onBackPress(options) {
//页面点击返回事件
if (this.showMask) {
this.showMask = false;
} else {
uni.showModal({
title: '提示',
content: '是否退出uni-app?',
success: function(res) {
if (res.confirm) {
// 退出当前应用,改方法只在App中生效
//plus.runtime.quit();
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
}
return true;
},
methods: {}
};
//双击返回键将app退回后台
export default {
data() {
return {
one_back:false,
};
},
onBackPress(e) {
console.log(e)
if(this.one_back){
let main = plus.android.runtimeMainActivity();
main.moveTaskToBack(false);
}else{
uni.showToast({
title:'再按一次返回键退出康雅医养',
icon:'none',
})
this.one_back=true;
setTimeout(()=>{
this.one_back=false;
},1500)
}
return true;
},
methods: {}
};
相关文章
发表评论
评论列表
- 这篇文章还没有收到评论,赶紧来抢沙发吧~