admin管理员组文章数量:1356933
I'm working on a static website fetching content from the WordPress API.
On the menu of the website, I want the content to be save on a nuxt store, and available on the nav ponent.
I reed the doc of the nuxt server and the nuxtServerInit action, but I didn't find a nice example of how to make a axion call inside this action, and be able to fetch the store on the ponent.
I find this, but it's not working .. .js/issues/2307
Thanks a lot for your help.
I'm working on a static website fetching content from the WordPress API.
On the menu of the website, I want the content to be save on a nuxt store, and available on the nav ponent.
I reed the doc of the nuxt server and the nuxtServerInit action, but I didn't find a nice example of how to make a axion call inside this action, and be able to fetch the store on the ponent.
I find this, but it's not working .. https://github./nuxt/nuxt.js/issues/2307
Thanks a lot for your help.
Share Improve this question asked Aug 20, 2018 at 13:00 Kévin FuretKévin Furet 3451 gold badge8 silver badges21 bronze badges 1- You can use property asyncData for load content. Link nuxtjs/guide/async-data – Николай Commented Aug 20, 2018 at 14:05
1 Answer
Reset to default 9Try this
store/index.js
export const state = () => ({
data: null
})
export const actions = {
// nuxtServerInit is called by Nuxt.js before server-rendering every page
async nuxtServerInit({ mit, dispatch }) {
await dispatch('storeDispatchFunc')
},
// axios...
async storeDispatchFunc({ mit }) {
const { data } = await this.$axios.get('/api/wp....')
mit('SET_DATA', data)
},
}
export const mutations = {
SET_DATA(state, theData) {
state.data = theData
}
}
本文标签: javascriptMake a http call with axios in the nuxtServerInit actionStack Overflow
版权声明:本文标题:javascript - Make a http call with axios in the nuxtServerInit action - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743957954a2568478.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论