0👍
I think a good solution would be to use a Mixin. You can do a global Mixin as follows.
Vue.mixin({
methods: {
async fetchData() {
const playlists = await api.getAllPlaylists();
}
}
});
Put this before your main Vue instance and it will be available to any of your components.
If you don’t want it to be available globally define it as below.
var fetchData = {
methods: {
async fetchData() {
const playlists = await api.getAllPlaylists();
}
}
}
Then include it in your component definitions
export default {
mixins: [fetchData],
data(){
//...
}
}
More on Mixins https://v2.vuejs.org/v2/guide/mixins.html
- [Vuejs]-Vuejs loop over in data results not on how many fields i have
- [Vuejs]-What's missing with my project.json building using nuxtjs?
Source:stackexchange.com