I have in my actions.js
import axios from 'axios'
export default {
nuxtServerInit ({ commit, state }, { app }) {
axios.get(`http://api.example.com/articles/sections`)
.then((res) => {
commit('SET_SECTIONS', res.data)
})
}
}
But it doesn't work. I also tried @nuxt/axios module, same.
Maybe use a return before axios.get(...) or:
import axios from 'axios'
export default {
async nuxtServerInit ({ commit, state }, { app }) {
let res = await axios.get(`http://api.example.com/articles/sections`)
commit('SET_SECTIONS', res.data)
}
}
Async function calls must returns a Promise
@EllenFawkes yes, it works this way. I guess it's time to begin to use async/await in my code =) Thanks!
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Maybe use a
returnbefore axios.get(...) or:Async function calls must returns a
Promise