vuex-module-decorators nuxt example
Example: vuex-module-decorators nuxt axios
import { NuxtAxiosInstance } from '@nuxtjs/axios'
let $axios: NuxtAxiosInstance
export function initializeAxios(axiosInstance: NuxtAxiosInstance) {
$axios = axiosInstance
}
export { $axios }
------------------------
import { Plugin } from '@nuxt/types'
import { initializeAxios } from '~/utils/api'
const accessor: Plugin = ({ $axios }) => {
initializeAxios($axios)
}
export default accessor
------------------------------
...
plugins: [
{ src: '@/plugins/axios-accessor.ts' }
]
-----------------------------------------
import { $axios } from '../../utils/api'
export default class user extends VuexModule {
@Action
something() {
return $axios.$get('/somethnig')
}
}