uniapp中webview支持history.back的方法
发表于:2022-02-15 13:35:11浏览:4603次
在uni-app中使用了webview之后, 由于项目完全由app内嵌h5完成, 所以无法控制app的物理返回键; 要实现这个功能,最主要的是完成应用与H5 的通讯问题。
<template>
<view></view>
</template>
<script>
export default {
data () {
return {
wv: null
}
},
onLoad() {
// #ifdef APP-PLUS
const url = '网址';
const wv = plus.webview.create("", "custom-webview", {
plusrequire: "none", //禁止远程网页使用plus的API,
'uni-app': 'none', //不加载uni-app渲染层框架
})
wv.loadURL(url);
const currentWebview = this.$scope.$getAppWebview();
currentWebview.append(wv);
this.wv = wv
// #endif
},
onBackPress() {
var _this = this;
_this.wv.canBack(function(e){
console.log(e);
if(e.canBack)
{
_this.wv.back()
}
else
{
uni.showModal({
'title':'确定要退出应用吗?',
success:function(e){
if(e.confirm)
{
plus.runtime.quit();
}
}
})
}
})
return true;
},
onNavigationBarButtonTap (e) {
uni.navigateBack()
}
}
</script>推荐文章
- uniapp中webview支持history.back的方法
- Thinkphp6集成JWT API接口引入token
- 使用table2excel实现layui数据表格导出复杂表头EXCEL
- 微信浏览器或手机浏览器字体大小调整 导致H5页面布局错乱解决方案
- PHP中,如果存在继承关系,其中子类和父类都定义了构造函数__construct(),怎么处理?
- thinkphp6创建并设置执行定时任务的方法
- TP6便捷快速查询日、月、年数据的方法
- 前端对返回的json数据预防XSS攻击
- 图片变形处理,可设置CSS属性object-fit: cover完美解决
- Vue history模式下实现微信授权登录

