可以通过从vue-router中beforeRouteEnter钩子函数中的from参数中获取url,利用next()传递回当前组件,具体代码如下:

<sctipt>
    export default {
        data() {
            return {
                beforeUrl: ''
            }
        },
        beforeRouteEnter (to, from, next) {
            next(vm => {
                vm.beforeUrl = from.path
            })
        },
        mounted() {
            this.$nextTick(() => {
                console.log(this.beforeUrl)
            })
        }
    }
</script>

 

Logo

前往低代码交流专区

更多推荐