uniapp webview页面从组件页面回退时不刷新解决办法

<template>
		  <!-- 事件处理 -->
	  <web-view v-if="url.length>0" :src="url" ></web-view>
</template>

<script>
var _self;	
	import {mapState,mapMutations} from 'vuex'	
    export default {
        data() {
            return {
				url:'/hybrid/html/pages/work/problemHandle/problemHandle.html',
				index:0,
            }
        },
		computed: mapState(['forcedLogin','username','token']),
		onLoad() {
            _self = this;
			let userpass = uni.getStorageSync("userpass");
			
			this.url = `/hybrid/html/pages/work/problemHandle/problemHandle.html?token=${this.token}&realname=${encodeURI(encodeURI(userpass.userInfo.realname))}&rolename=${encodeURI(encodeURI(userpass.role[0].role_name))}`
		},
		onShow(el) {//页面打开
			let allObj = uni.getStorageSync("uni_allTemporary_onShow_Updata");
			let userpass = uni.getStorageSync("userpass");
			if (JSON.stringify(allObj) != '{}') {
				//更新页面
				_self.url = '';
				setTimeout(() => {
					_self.index = (_self.index + 1);
					_self.url = `/hybrid/html/pages/work/problemHandle/problemHandle.html?index=${_self.index}&realname=${encodeURI(encodeURI(userpass.userInfo.realname))}&rolename=${encodeURI(encodeURI(userpass.role[0].role_name))}&token=${_self.token}`;
				}, 500);
				uni.setStorageSync("uni_allTemporary_onShow_Updata",{});
			}
			uni.setStorageSync("uni_allTemporary_onShow_Updata",{});
		},
        methods: {

        },
    }
</script>

<style>
    
	
</style>

初次进入页面时只有onload执行,不需要onshow执行所以加了uni.getStorageSync()来限制onshow执行。后面返回时只有onshow会执行,由于地址相同页面可能不会刷新,加入index使地址发生变化。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值