我想在asyncData中访问我的Vuex数据,但是我不能访问,而且我似乎不能在asyncData中使用axios模块。
我试了很多次。
pages/index.vue
export default {
asyncData() {
//in my project there's a lot more code here but i think this is enough
let id = this.$store.state.id //i know i should prob use getter but no
//here i want to do an axios req with this var "id" but axios doesnt work
return axios.get(`url${id}`)
.then(...) //not gonna write it out here
}
}store/index.js
export const const = () => ({
id: "#5nkI12_fSDAol/_Qa?f"
})我希望它从Vuex获得ID,然后执行Axios req。整个应用程序都不起作用。
发布于 2019-07-28 17:46:16
context提供了从Nuxt到Vue组件的附加对象/参数。上下文可在特殊的Nuxt生命周期区域中使用,如asyncData、fetch、plugins、middleware、modules和nuxtServerInit。
export default {
asyncData({ store }) {
const id = store.state.id
return axios.get(`url${id}`)
.then(...)
}
}https://stackoverflow.com/questions/57242050
复制相似问题