<template>
<view>
<!-- 在你的页面模板中添加一个返回按钮 -->
<button type="primary" @tap="onClick">返回</button>
<web-view :src="src" :webview-styles="webviewStyles"></web-view>
</view>
</template>
<script>
export default {
data() {
return {
src: '自己的路径',
webviewStyles: {
progress: {
color: '#FF3333'
}
},
// 将原生视图对象引用提升到实例级别,以便在onUnload中访问
nativeView: null
};
},
onLoad() {
this.creatView();
},
onUnload() {
// 确保nativeView已被创建且非null才执行销毁操作
if (this.nativeView) {
this.nativeView.close();
this.nativeView = null; // 清除引用
}
},
methods: {
creatView() {
this.nativeView = new plus.nativeObj.View('test', {
top: '20px',
left: '10px',
height: '50px',
width: '50px'
});
// 绘制文本
this.nativeView.drawRect({
color: 'rgba(0,0,0,0.8)',
radius: '25px'
}, {
top: '0px',
left: '0px',
width: '50px',
height: '50px'
});
this.nativeView.drawText('返回', {}, {
size: '13px',
color: '#ffffff'
});
this.nativeView.show();
// plus.nativeUI.toast('创建成功');
this.nativeView.addEventListener("click", this.onClick, false);
},
onClick(e) {
console.log('e', e);
uni.redirectTo({
url: `/pages/index/index?swiperIndex=2`
})
}
}
}
</script>
<style lang="scss">
</style>
uniapp webview页面返回app
最新推荐文章于 2024-08-08 16:07:35 发布