{"action":"created","issue":{"url":"https://api.github.com/repos/nuxt-community/axios-module/issues/16","repository_url":"https://api.github.com/repos/nuxt-community/axios-module","labels_url":"https://api.github.com/repos/nuxt-community/axios-module/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/nuxt-community/axios-module/issues/16/comments","events_url":"https://api.github.com/repos/nuxt-community/axios-module/issues/16/events","html_url":"https://github.com/nuxt-community/axios-module/issues/16","id":254997497,"number":16,"title":"How can I use axios?","user":{"login":"ahDDD","id":15305662,"avatar_url":"https://avatars1.githubusercontent.com/u/15305662?v=4","gravatar_id":"","url":"https://api.github.com/users/ahDDD","html_url":"https://github.com/ahDDD","followers_url":"https://api.github.com/users/ahDDD/followers","following_url":"https://api.github.com/users/ahDDD/following{/other_user}","gists_url":"https://api.github.com/users/ahDDD/gists{/gist_id}","starred_url":"https://api.github.com/users/ahDDD/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahDDD/subscriptions","organizations_url":"https://api.github.com/users/ahDDD/orgs","repos_url":"https://api.github.com/users/ahDDD/repos","events_url":"https://api.github.com/users/ahDDD/events{/privacy}","received_events_url":"https://api.github.com/users/ahDDD/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-09-04T10:17:08Z","updated_at":"2017-09-05T02:32:27Z","closed_at":null,"author_association":"NONE","body":"I could not find an accurate way to introduce and use axios\r\nIn my code:\r\n_nuxt.config.js_\r\n```\r\nmodules: [\r\n    '@nuxtjs/proxy',\r\n    '@nuxtjs/axios'\r\n  ],\r\n  proxy: {\r\n    '/api/**': 'http://127.0.0.1:8000'\r\n  },\r\n  axios: {\r\n    requestInterceptor: (config, { store }) => {\r\n      if (store.state.token) {\r\n        config.headers.common['Authorization'] = `JWT ${store.state.token}`\r\n      }\r\n      return config\r\n    }\r\n  },\r\n```\r\n\r\n_login.vue_\r\n```\r\nimport { mapActions } from 'vuex'\r\nmethods: {\r\n    ...mapActions([\r\n      'login'\r\n    ]),\r\n    handleLogin () {\r\n        this.login({ user: this.formData, axios: this.$axios })\r\n    }\r\n}\r\n```\r\n\r\n_store/index.js_\r\n```\r\nactions: {\r\n    async login ({ commit }, { user, axios }) {\r\n      try {\r\n        const response = await axios.post('/account/login/', user)\r\n        const data = response.data\r\n        commit('INIT', data)\r\n        return Promise.resolve()\r\n      } catch (error) {\r\n        return Promise.reject(error.response.data)\r\n      }\r\n}\r\n```\r\nI wondered if I had to call axios in this way\r\nIs there a simple way to call axios in index.js?\r\nI tried:\r\n_store/index.js_\r\n```\r\nactions: {\r\n    async login ({ commit }, user) {\r\n      try {\r\n        const response = await this.$axios.$post('/account/login/', user)\r\n        const data = response.data\r\n        commit('INIT', data)\r\n        return Promise.resolve()\r\n      } catch (error) {\r\n        return Promise.reject(error.response.data)\r\n      }\r\n}\r\n```\r\nand:\r\n_login.vue_\r\n```\r\nthis.login(this.formData)\r\n```\r\nBut i got _TypeError: Cannot read property '$axios' of undefined_\r\nIs not what I missed some steps?Can let me know? Thanks!"},"comment":{"url":"https://api.github.com/repos/nuxt-community/axios-module/issues/comments/327056003","html_url":"https://github.com/nuxt-community/axios-module/issues/16#issuecomment-327056003","issue_url":"https://api.github.com/repos/nuxt-community/axios-module/issues/16","id":327056003,"user":{"login":"ahDDD","id":15305662,"avatar_url":"https://avatars1.githubusercontent.com/u/15305662?v=4","gravatar_id":"","url":"https://api.github.com/users/ahDDD","html_url":"https://github.com/ahDDD","followers_url":"https://api.github.com/users/ahDDD/followers","following_url":"https://api.github.com/users/ahDDD/following{/other_user}","gists_url":"https://api.github.com/users/ahDDD/gists{/gist_id}","starred_url":"https://api.github.com/users/ahDDD/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahDDD/subscriptions","organizations_url":"https://api.github.com/users/ahDDD/orgs","repos_url":"https://api.github.com/users/ahDDD/repos","events_url":"https://api.github.com/users/ahDDD/events{/privacy}","received_events_url":"https://api.github.com/users/ahDDD/received_events","type":"User","site_admin":false},"created_at":"2017-09-05T02:32:27Z","updated_at":"2017-09-05T02:32:27Z","author_association":"NONE","body":"I found that I tried to `console.log (this)` in store / index.js, but only get a `undefined`\r\n```\r\nimport Vue from 'vue'\r\nimport Vuex from 'vuex'\r\nVue.use(Vuex)\r\nconst store = () => new Vuex.Store({\r\n  state: {\r\n  // something\r\n  },\r\n  mutations: {\r\n  // something\r\n  }\r\n})\r\nexport default store\r\n```\r\nIs it because the way to create vuex causes i can not access `this` in vue instance?"}}
{"actor":{"display_login":"ahDDD"}}