返回

阻止浏览器回退

以在vue中的应用为例:

mounted() {
history.pushState(null, null, document.URL)
window.addEventListener('popstate', this.close)
},

destroyed() {
window.removeEventListener('popstate', this.close)
},

methods: {
close() {
this.$emit('close')
  },

handleBackClick() {
window.history.go(-1)
this.close()
  }
}
分类: 前端