监听手机点击返回按钮

在页面加载时进行监听

if (window.history && window.history.pushState) {
 	history.pushState(null, null, document.URL) 
	window.addEventListener('popstate', this.eventBackButton, false) // false阻止默认事件
}

页面销毁前或者销毁后取消监听

destroyed() {
    window.removeEventListener('popstate', this.eventBackButton, false) // false阻止默认事件
}

方法里执行监听到点击返回按钮时执行的方法

// 监听手机点击返回按钮
eventBackButton() {
    wx.closeWindow()
},
发布了35 篇原创文章 · 获赞 17 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_39024950/article/details/102604424
今日推荐