vue从其它页面返回_vue页面按返回键等跳转重定向判断
情景:用戶購物車-結算頁-支付后跳轉到跳轉到訂單列表,當按返回時重定向到首頁
1.使用this.$router.replace()
2.
mounted() {
// 掛載完成后,判斷瀏覽器是否支持popstate
if (window.history && window.history.pushState) {
history.pushState(null, null, document.URL);
window.addEventListener('popstate', this.goBack, false);
}
},
// 頁面銷毀時,取消監聽。否則其他vue路由頁面也會被監聽
destroyed(){
window.removeEventListener('popstate', this.goBack, false);
},
methods: {
goBack(){
// 個人中心進入返回上一級,支付后進入返回首頁
if (!this.$route.query.type) {
this.$router.replace({path: '/'})
} else {
history.go(-1);
}
},
toindex() {
this.$router.push('/articles/myticket')
},
toarticles() {
this.$router.push('/articles')
}
},
總結
以上是生活随笔為你收集整理的vue从其它页面返回_vue页面按返回键等跳转重定向判断的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: webuploader 获取文件md5_
- 下一篇: vue 封装dialog_自己封装dia