Tambahkan di main.ts
import axios from 'axios'
const pinia = createPinia()
const app = createApp(App)
.use(IonicVue)
.use(router)
.use(pinia);
const axiosInstance = axios.create({
withCredentials: true,
})
router.isReady().then(() => {
app.component('Loading', Loading)
app.config.globalProperties.$axios = { ...axiosInstance }
app.mount('#app');
})
Tinggal pake di component
async mounted() {
await this.$axios.get('//jsonplaceholder.typicode.com/users')
},
Sebagai catatan: keyword this gak jalan di setup dan jangan taruh di dalam defineComponent gunakan export default { } biasa
Komentar