vue获取上一级页面
data(){
return{
fromPath: '',
}
},
beforeRouteEnter(to, from, next) {
next(vm => {
// 通过 `vm` 访问组件实例,将值传入fromPath
vm.fromPath = from.path
})
},
mounted() {
this.$nextTick(() => {
// 验证是否获取到了上页的url
/* eslint-disable no-console */
console.log('this.fromPath', this.fromPath)
})
}