showing results for - "vuex module decorators nuxt axios"
Candis
02 Sep 2018
1// /utils/api.ts
2
3import { NuxtAxiosInstance } from '@nuxtjs/axios'
4
5let $axios: NuxtAxiosInstance
6
7export function initializeAxios(axiosInstance: NuxtAxiosInstance) {
8  $axios = axiosInstance
9}
10
11export { $axios }
12------------------------
13
14// /plugins/axios-accessor.ts
15import { Plugin } from '@nuxt/types'
16import { initializeAxios } from '~/utils/api'
17
18const accessor: Plugin = ({ $axios }) => {
19  initializeAxios($axios)
20}
21
22export default accessor
23------------------------------
24
25// /nuxt.config.ts
26...
27  plugins: [
28    { src: '@/plugins/axios-accessor.ts' }
29  ]
30-----------------------------------------
31// /store/user.ts
32import { $axios } from '../../utils/api'
33
34export default class user extends VuexModule {
35 
36  @Action
37  something() {
38  	return $axios.$get('/somethnig')
39  }
40}