I have a problem using Nuxt.js with TypeScript. In my project I use dependencies like axios or nuxt-i18n. For this example I am using Axios. I configured it like in the documentation for nuxt/axios
nuxt.config.js
export default {
modules: ['@nuxtjs/axios']
axios: {},
}
tsconfig.json
{
"compilerOptions": {
"types": [
"@nuxt/types",
"@nuxtjs/axios"
]
}
}
Now I want to use $axios in my Vuex store like this:
{
actions: {
async getIP ({ commit }) {
const ip = await this.$axios.$get('http://icanhazip.com')
commit('SET_IP', ip)
}
}
}
But now I get the error:
`TS2339: Property '$axios' does not exist on type '{ getIP(state: any, { commit }: { commit: any; }): Promise ; }'.`
Edit: The comments say, that using an arrow function should help. I tried it like this:
export const actions = {
getIP: async ({commit}) => {
const ip = await this.$axios.$get('http://icanhazip.com')
...
}
};
but now the following error appears on "this."
TS7041: The containing arrow function captures the global value of 'this'.