vuex-module-decoratorss nuxt code example

Example: vuex-module-decorators nuxt axios

// /utils/api.ts

import { NuxtAxiosInstance } from '@nuxtjs/axios'

let $axios: NuxtAxiosInstance

export function initializeAxios(axiosInstance: NuxtAxiosInstance) {
  $axios = axiosInstance
}

export { $axios }
------------------------

// /plugins/axios-accessor.ts
import { Plugin } from '@nuxt/types'
import { initializeAxios } from '~/utils/api'

const accessor: Plugin = ({ $axios }) => {
  initializeAxios($axios)
}

export default accessor
------------------------------

// /nuxt.config.ts
...
  plugins: [
    { src: '@/plugins/axios-accessor.ts' }
  ]
-----------------------------------------
// /store/user.ts
import { $axios } from '../../utils/api'

export default class user extends VuexModule {
 
  @Action
  something() {
  	return $axios.$get('/somethnig')
  }
}