data() {
return {
Ipeainav: uni.getStorageSync('Ipeainav'),
url: '',
}
},
onLoad(option) {
this.url = option.url
},
onReady() {
let that = this;
// #ifdef APP-PLUS
var currentWebview = this.$scope
.$getAppWebview() //此对象相当于html5plus里的plus.webview.currentWebview()。在uni-app里vue页面直接使用plus.webview.currentWebview()无效
setTimeout(function() {
wv = currentWebview.children()[0]
wv.setStyle({
top: 150,
height: 300
})
}, 1000); //如果是页面初始化调用时,需要延时一下
// #endif
uni.setNavigationBarTitle({
title: that.title
})
that.clearMuiBack()
},
onBackPress(options) {
if (options.from === 'navigateBack') {
// 当从navigateBack触发时,这里可以不作处理或者添加额外逻辑
return false;
}
this.handleBackButton();
return true; // 表示已处理该事件
},
onUnload() {
uni.setStorageSync('gasValue', 1)
},
methods: {
clearMuiBack() {
// #ifdef APP-PLUS
var currentWebview = this.$scope.$getAppWebview().children()[0];
setTimeout(() => {
//监听注入的js
currentWebview.addEventListener("loaded", function() {
currentWebview.evalJS("mui.init({keyEventBind: {backbutton: false }});");
});
}, 1000)
// #endif
},
handleBackButton() {
uni.showModal({
title: '提示',
content: '确定要离开此页面吗?',
success: function(res) {
if (res.confirm) {
uni.navigateBack(); // 用户确认后,正常返回
} else {
// 用户取消了操作,什么也不做
}
}
});
return false; // 阻止默认返回行为
},
}
}

2***@qq.com
- 发布:2025-02-27 10:58
- 更新:2025-02-27 10:58
- 阅读:72
0 个回复