soumya0373
04/01/2024, 1:45 PMimport axios from 'axios'
import { setupCache } from 'axios-cache-interceptor/dev'
export default function ({ $config }, inject) {
// Create axios instance
const axiosInstance = axios.create({
baseURL: $config.baseURL,
})
// Set up caching
// Set axios instance to Nuxt context
const axiosWithCache = setupCache(axiosInstance, {
methods: ['get', 'post'],
debug: console.log,
})
inject('axiosCache', axiosWithCache)
}
rp_st
04/01/2024, 3:14 PMsoumya0373
04/01/2024, 3:14 PMrp_st
04/01/2024, 3:15 PMsoumya0373
04/01/2024, 3:15 PMsoumya0373
04/01/2024, 3:19 PMsoumya0373
04/01/2024, 3:19 PMsoumya0373
04/01/2024, 3:20 PMsoumya0373
04/01/2024, 3:20 PM<template>
<div>
<div v-if="loading">Loading..</div>
<div v-else>{{ data }}</div>
</div>
</template>
<script>
import axios from 'axios'
import { setupCache } from 'axios-cache-interceptor/dev'
const axiosInstance = axios.create()
const axiosWithCache = setupCache(axiosInstance, {
debug: console.log,
})
export default {
layout: 'navbar',
data() {
return {
data: null,
loading: false,
}
},
mounted() {
this.fetchProjects()
},
methods: {
async fetchProjects() {
this.loading = true
this.data = await axiosWithCache.get(
'/api/project/all?limit=12&start_at=' + 1 + '&search_key='
)
this.loading = false
},
},
}
</script>
soumya0373
04/01/2024, 3:21 PMrp_st
04/01/2024, 3:22 PMrp_st
04/01/2024, 3:22 PMsoumya0373
04/01/2024, 3:23 PMsoumya0373
04/01/2024, 3:23 PMsoumya0373
04/01/2024, 3:23 PM