uniapp的APP中使用webview的返回的问题

作者 : admin 本文共589个字,预计阅读时间需要2分钟 发布时间: 2024-03-28 共3人阅读

在使用uniapp开发APP中很多时候使用webview内嵌网页,
在网页中点击多次跳转后,想点击上方的返回按钮返APP的上一页或上几页的实现方法:

<template>
	<view>
		<web-view v-if="newurl" :src="newurl" ></web-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				newurl:''
			}
		},
		onBackPress(e) {//响应返回事件
			if (e.from === 'navigateBack') {  //这个地方必须要有的,否则会死循环
				return false;  
			} 
			console.log('点击返回....');
			let pages = getCurrentPages()
			let page = pages[pages.length - 1];
			let currentPages = page.$getAppWebview()
			currentPages.close()
			uni.navigateBack({delta:2})
			return true;
		},
		onShow() {
		},
		onLoad(opts) {
			this.newurl = "https://www.xxx.com/index'
		},
		methods: {}
	}
</script>
<style>
	page{
		background-color: #FFF;
	}
</style>

本站无任何商业行为
个人在线分享 » uniapp的APP中使用webview的返回的问题
E-->