问题
I'm not able to use
this.$route.params
route.params
router.params
how do I get the params of $route in my actions?
回答1:
in your actions.js or store.js
import router from 'path/to/router'
console.log(router.currentRoute.params)
回答2:
You can access the current route through the state or rootState with Vuex.
If the action is in a module, use rootState:
MY_ACTION: ({rootState}) => new Promise((resolve, reject) => {
let params = rootState.route.params
// do stuff
}
If the action is not in a module, use state:
MY_ACTION: ({state}) => new Promise((resolve, reject) => {
let params = state.route.params
// do stuff
}
See https://vuex.vuejs.org/api/#actions for more information on the context object.
来源:https://stackoverflow.com/questions/50824234/how-to-get-vue-router-params-in-vuex