优化不刷新问题

This commit is contained in:
java110 2021-09-05 01:16:30 +08:00
parent b089996df9
commit 9a22a5d77b
2 changed files with 38 additions and 14 deletions

View File

@ -1,17 +1,24 @@
<template>
<view class="h5-html">
 <web-view ref="webview"  :src="url"  @onPostMessage="onReciveMessage"></web-view>
 <web-view ref="webview" id="homemarkingWebView" class="wuixw"  :src="url"  @onPostMessage="onReciveMessage">
</web-view>
</view>
</template>
<script>
import conf from '../../conf/config.js'
import {
reciveMessage,getHcCode
reciveMessage,
getHcCode
} from '../../api/webView/webViewApi.js'
import {decodeUrl} from '../../utils/UrlUtil.js';
import {
decodeUrl
} from '../../utils/UrlUtil.js';
import {
getStorageSync,
setStorageSync
} from '../../utils/StorageUtil.js'
export default {
data() {
return {
@ -23,24 +30,33 @@
let _that = this;
let _url = options.url;
_url = decodeUrl(_url);
setStorageSync('_go_back_refresh', 0);
//hcCode
this.vc.getCurCommunity()
.then(function(_communityInfo) {
_that.communityId = _communityInfo.communityId;
})
.then(function() {
_that.url = conf.mallUrl+"#/pages/homemaking/index?mallFrom=HC&hcCommunityId="+_that.communityId;
_that.url = conf.mallUrl + "#/pages/homemaking/index?mallFrom=HC&hcCommunityId=" + _that
.communityId;
})
},
onShow() {
let that = this;
let _goBackRefresh = getStorageSync('_go_back_refresh');
if(_goBackRefresh == 1){
let wv = this.$refs.webview
wv.reload(true);
if (_goBackRefresh == 1) {
// #ifdef H5
document.getElementsByTagName('iframe').forEach(item => {
console.log(item.id);
if('homemarkingWebView' == item.id){
item.contentWindow.location.href = that.url;
}
})
// #endif
}
setStorageSync('_go_back_refresh',0)
setStorageSync('_go_back_refresh', 0);
},
methods: {
onReciveMessage: function(event) {
@ -55,4 +71,4 @@
width: 100%;
height: 100%;
}
</style>
</style>

View File

@ -1,6 +1,6 @@
<template>
<view class="h5-html">
 <web-view ref="webview"  :src="url"  @onPostMessage="onReciveMessage"></web-view>
 <web-view ref="webview" id="mallWebView" :src="url"  @onPostMessage="onReciveMessage"></web-view>
</view>
</template>
@ -30,6 +30,7 @@
let _that = this;
let _url = options.url;
_url = decodeUrl(_url);
setStorageSync('_go_back_refresh', 0);
//hcCode
this.vc.getCurCommunity()
.then(function(_communityInfo) {
@ -41,10 +42,17 @@
},
onShow() {
let that = this;
let _goBackRefresh = getStorageSync('_go_back_refresh');
if (_goBackRefresh == 1) {
let wv = this.$refs.webview
wv.currentWebview().reload(true);
// #ifdef H5
document.getElementsByTagName('iframe').forEach(item => {
console.log(item.id);
if('mallWebView' == item.id){
item.contentWindow.location.href = that.url;
}
})
// #endif
}
setStorageSync('_go_back_refresh', 0);