Answers for "vuex-module-decorators nuxt axios"

1

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')
  }
}
Posted by: Guest on January-28-2021

Code answers related to "vuex-module-decorators nuxt axios"

Code answers related to "Javascript"

Browse Popular Code Answers by Language