0👍
if u dont want to fetch data everytime, you could use the store like this
in created hook where you want to fetch your data check if data is already stored or not …
computed: mapState([
'yourData'
]),
created(){
if(!yourData){
// now you can fetch everything you want
}
}
0👍
I solved my problem using nuxtServerInit method in the store. I also replaced my anchor tags with nuxt-link
//store/index.js
...
async nuxtServerInit({ commit }) {
try {
await this.$axios.get("regions/get-all", config).then((res) => {
if (res.status === 200) {
commit("setRegions", res.data.regions);
}
});
} catch (e) {
console.log(e);
}
},
Source:stackexchange.com