vux, vue如何控制微信自带的返回按钮,让其返回其他页面?
<script> import { mapState } from 'vuex' export default{ name: 'clockFx', data () { return { } }, computed: mapState({ listenFlag: state => state.listenFlag }), methods: { verify: function () { let thisObj = this if (this.listenFlag) { window.popstate = function () { thisObj.cancelBack() window.location.href = '#/LearningContent' //要跳转的链接 } window.addEventListener('popstate', window.popstate, false) } }, cancelBack: function () { this.$store.commit('listenFlag', false) window.removeEventListener('popstate', window.popstate) } }, created: function () { this.verify() }, watch: { '$route': 'verify' } } </script>
如果还写了其他的方法,那每个方法里面都要加上 thisObj.cancelBack() 这句话,是为了阻止其他事件触发返回按钮的事件