How to approach axios in the action of the nuxt store

Viewed 211

First, the axios setup was carried out according to the document nuxtjs as follows.

nuxt.config.js

modules: [
    '@nuxtjs/axios',
  ],

  axios: {
    // extra config e.g
    // BaseURL: 'https://link-to-API'
  }

And I tried to build a store and approach axios in action, but I met undefined. user.ts

import { Module, VuexAction } from 'nuxt-property-decorator';

@Module({
  name: 'user',
  stateFactory: true,
  namespaced: true
})
export default class User extends VuexModule {

  @VuexAction({  rawError: true })
  private async axiosSideInfo({}) {
    this.$axios < ---------------- undefined
      .post( ... )
      )
  }
}

Something's wrong...

doc

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