Usage

Last updated 3 months ago

Component

asyncData

async asyncData({ app }) {
const ip = await app.$axios.$get('http://icanhazip.com')
return { ip }
}

methods/created/mounted/etc

methods: {
async fetchSomething() {
const ip = await this.$axios.$get('http://icanhazip.com')
this.ip = ip
}
}

Store nuxtServerInit

async nuxtServerInit ({ commit }, { app }) {
const ip = await app.$axios.$get('http://icanhazip.com')
commit('SET_IP', ip)
}

Store actions

// In store
{
actions: {
async getIP ({ commit }) {
const ip = await this.$axios.$get('http://icanhazip.com')
commit('SET_IP', ip)
}
}
}