I have a basic bootstrap Spinner.vue component
<template>
<div class="modal" v-if="start">
<div class="spinner-border text-info" role="status" style="width: 3rem; height: 3rem;">
<span class="visually-hidden">Loading...</span>
</div>
</div>
</template>
<script>
export default {
name: 'Spinner',
props: {
start: {
type: Boolean,
default: true,
},
},
}
</script>
Considering the scale of my application, it might not be efficient to import this component into every component or page where a spinner is needed for data fetching. I also would like to prefetch data and pass it directly to a page using Vue Router like shown below:
const routes = [
{
name: RouteNames.XYZ,
path: '/xyz',
beforeEnter: async (to) => {
let data = await Service.getList();
to.params.list= data.list;
},
component: xyzList,
},
]
It would be advantageous if my service wrapper class had methods to showSpinner and hideSpinner that can be used in all data-fetching methods such as Service.getList(). Is there a way to achieve this? Can I somehow incorporate my Spinner component into this JavaScript service class?
If possible, I would prefer to implement this functionality without relying on an external spinner library."