在web-view中点击左上角需要点击两次才能返回的问题解决
这是写在h5页面里面的
window.addEventListener('popstate', (event) => {
wx.miniProgram.navigateBack();
});
const code = getSearch('code'); // 伪代码,获取查询参数
if (!code) {
// 页面A1
if (isWeixin()) {
// 微信环境
const redirectUrl = window.location.href + '&code=1';
window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize' + '?appid=' + appId +
'&redirect_uri=' + encodeURIComponent(redirectUrl) +
'&response_type=code&scope=snsapi_userinfo' +
'#wechat_redirect'; // 静默授权伪代码
} else {
alert('当前不是微信环境');
}
} else {
// 页面A2
history.pushState({
page: 1}, null, window.location.href);
}
web-veiw路由的缓存问题解决
参考了别人大神的代码
<template>
<div class="video">
<web-view :src="webViewUrl" v-if="webViewUrl.length"></web-view>
</div>
</template>
<script>
export default {
data() {
return {
webViewUrl: "",
};
},
mounted() {
},
onLoad(option) {
// this.webViewUrl = `https://www.hnytbd.com/index.html?equipmentSncode=${
// this.$route.query.code
// }&r=${Math.random()}`;
if (wx.getStorageSync("isJournalBack")) {
wx.removeStorageSync("isJournalBack");
}
let str = "https://www.hnytbd.com/index.html";
if (JSON.stringify(option) !== "{}") {
str += "?";
for (var i in option) {
str += i + "=" + option[i] + "&";
}
str = str.slice(0, str.length - 1);
}
this.webViewUrl = `${
decodeURIComponent(str)}`;
},
onShow() {
// this.onLoad();
if (wx.getStorageSync("isJournalBack")) {
let urlTemp = this.webViewUrl;
this.webViewUrl = "";
wx.removeStorageSync("isJournalBack");
setTimeout(() => {
this.webViewUrl =
urlTemp.split("?")[0] +
"?flag=" +
Date.parse(new Date()) +
"&" +
urlTemp.split("?")[1];
console.log(this.webViewUrl);
}, 100);
}
},
};
</script>