[Vuejs]-Can I cache an API call object using Vue JS lifecycle hooks?

0👍

the best thing in my opinion is to keep the calculated data in a service, so that you in your mounted component simply call the getData (), imported from the StrainService.js

// StrainService.js
let response = null;


const getData = async () => {
    if (!response) {
        response = await StrainApiCall()
    }

    return response
}


const StrainApiCall = () => {
    return axios.get('yourdata.com') // your api call
}


export {
    getData
}

Leave a comment