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

  • Post author:
  • Post category:uniapp


<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使地址发生变化。



版权声明:本文为m0_71138490原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。