我想访问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请求。整个应用都无法正常工作。
答案 0 :(得分:0)
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(...)
}
}