vue路由回退判断
在页面一开始加上一个全局的函数:
activated: function () {
this.$setgoindex()
}
这个函数是这样的,判断当前页面的历史记录是不是小于等于1,如果小于等于1,说明这个页面没有可以返回的上一页,如果没有可以返回的上一页,就给地址栏加上一个goindex=true的参数,这样你从这个页面在往下一个页面跳转在返回,这个参数就一直加上的
Vue.prototype.$setgoindex = function () {
if (window.history.length <= 1) {
if (location.href.indexOf('?') === -1) {
window.location.href = location.href + '?goindex=true'
} else if (location.href.indexOf('?') !== -1 && location.href.indexOf('goindex') === -1) {
window.location.href = location.href + '&goindex=true'
}
}
}
然后在左上角返回按钮加上这个逻辑:
if (this.$route.query.goindex === 'true') {
this.$router.push('/')
} else {
this.$router.back(-1)
}
这样就可以了
一辈子很短,努力的做好两件事就好;第一件事是热爱生活,好好的去爱身边的人;第二件事是努力学习,在工作中取得不一样的成绩,实现自己的价值,而不是仅仅为了赚钱;

浙公网安备 33010602011771号