SoFunction
Updated on 2025-04-05

Replace this operation in the global routing guard in vue (this.$store/this.$vux)

The global route guard this.$() reported an error, and this cannot be accessed

Solution

Declare variables instead of this

File method

((to, from, next) => {
 if(vue){
 vue.$()
 }else{

 }
 next()
})

let vue = new Vue({
 el: '#app',
 router,
 store,
 components: { App },
 template: '<App/>'
})

If judgment prevents the first initialization error

or

let vue = new Vue({
 el: '#app',
 router,
 store,
 components: { App },
 template: '<App/>'
})
((to, from, next) => {
 // if(vue){
 vue.$()
 // }else{

 // }
 next()
})

Supplementary knowledge:Solve that the navigation guard cannot use this.$store

In the navigation guards of vue router such as beforeEach(), it is impossible to operate vuex directly through this.$store because this point is inconsistent here.

The solution is to introduce an initialized store in the router

import store from '@/store'

Then you can get the router directly in the navigation guard

/**Navigation Guard */
((to, form, next) =&gt; {
 ()
})

The above article in vue's global routing guard replaces this operation (this.$store/this.$vux) is all the content I share with you. I hope you can give you a reference and I hope you can support me more.