I have data for currency
and I would like to share this data with all views without having to call the same function in each view.
My solution was to call the function in App.vue (my main view)
, but I am struggling to figure out how to pass it along with router-view
.
Code
HTML
<template>
<el-container :is="layout">
<transition name="fade">
<router-view id="content" :key="$route.fullPath"></router-view>
</transition>
</el-container>
</template>
Script
export default {
data() {
return {
isCollapse: true,
user: '',
type: '',
site_name: process.env.MIX_APP_NAME
}
},
created () {
this.getCurrency()
},
methods: {
getCurrency() {
axios
.get('/api/currencyDefault')
.then(response => {
this.currency = response.data.data
})
.catch(function (error) {
console.log('error', error);
});
},
}
}
Any insights on how to solve this?