一、因为小程序内嵌H5不支持“navigationStyle”: “custom”——隐藏原生导航栏了,所以有监听页面返回需求的解决办法。
<script src="https://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
methods: {
pushHistory(str = 'title', url = '#') {
let state = {
title: str,
url,
}
window.history.pushState(state, state.title, state.url)
},
goBack() {
wx.miniProgram.navigateBack()
},
},
created() {
let that = this
this.pushHistory()
window.addEventListener(
'popstate',
function(e) {
that.pushHistory('title1')
自定义方法, 直接关闭网页或返回小程序上一页
that.goBack()
},
false
)
},
二、延伸H5特性:Document.hidden 页面是否隐藏 true 或 false
document.addEventListener("visibilitychange", function() {
console.log( document.hidden );
});