I want to make an axios instance available globally in my Vue 3 app.
Setup:
import { createApp } from 'vue'
import axios from 'axios'
const axiosInstance = axios.create({
withCredentials: true,
})
const app = createApp()
app.config.globalProperties.$axios = axiosInstance
app.mount(el)
Usage:
let response = await this.$axios.get('/api/leads')
I get this error:
TypeError: this.$axios.get is not a function
Seems like this.$axios is undefined. I cannot figure out why.
Notes:
- I'm using the
@vue/compatbuild of Vue to migrate from Vue 2 to Vue 3. I'm following the official migration guide. - When inspecting
this.$axios- I getƒ wrap() ......