优化不刷新问题

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> <template>
<view class="h5-html"> <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> </view>
</template> </template>
<script> <script>
import conf from '../../conf/config.js' import conf from '../../conf/config.js'
import { import {
reciveMessage,getHcCode reciveMessage,
getHcCode
} from '../../api/webView/webViewApi.js' } 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 { export default {
data() { data() {
return { return {
@ -23,24 +30,33 @@
let _that = this; let _that = this;
let _url = options.url; let _url = options.url;
_url = decodeUrl(_url); _url = decodeUrl(_url);
setStorageSync('_go_back_refresh', 0);
//hcCode //hcCode
this.vc.getCurCommunity() this.vc.getCurCommunity()
.then(function(_communityInfo) { .then(function(_communityInfo) {
_that.communityId = _communityInfo.communityId; _that.communityId = _communityInfo.communityId;
}) })
.then(function() { .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() { onShow() {
let that = this;
let _goBackRefresh = getStorageSync('_go_back_refresh'); let _goBackRefresh = getStorageSync('_go_back_refresh');
if(_goBackRefresh == 1){ if (_goBackRefresh == 1) {
let wv = this.$refs.webview // #ifdef H5
wv.reload(true); 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: { methods: {
onReciveMessage: function(event) { onReciveMessage: function(event) {
@ -55,4 +71,4 @@
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
</style> </style>

View File

@ -1,6 +1,6 @@
<template> <template>
<view class="h5-html"> <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> </view>
</template> </template>
@ -30,6 +30,7 @@
let _that = this; let _that = this;
let _url = options.url; let _url = options.url;
_url = decodeUrl(_url); _url = decodeUrl(_url);
setStorageSync('_go_back_refresh', 0);
//hcCode //hcCode
this.vc.getCurCommunity() this.vc.getCurCommunity()
.then(function(_communityInfo) { .then(function(_communityInfo) {
@ -41,10 +42,17 @@
}, },
onShow() { onShow() {
let that = this;
let _goBackRefresh = getStorageSync('_go_back_refresh'); let _goBackRefresh = getStorageSync('_go_back_refresh');
if (_goBackRefresh == 1) { if (_goBackRefresh == 1) {
let wv = this.$refs.webview // #ifdef H5
wv.currentWebview().reload(true); 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); setStorageSync('_go_back_refresh', 0);