In my project, I have a function to download files. When the button is clicked, function onDownload
will be called:
import {useOnDownload} from "../../use/useOnDownload" setup() { ... const loading = ref(null) onDownload = (id) => { loading.value = id await useOnDownload(id) loading.value = null } return {loading, onDownload} }
I refactored the api code in the useOnDownload.js
calling file because other components also use the same code.
export async function useOnDownload(id) { // make api call to server with axios }
What did i do wrong? I need to wait for the function useOnDownload ... for the loader to work properly.
The following is how to use async wait syntax to create an asynchronous composable function
Clickherefor more information
I managed to solve another way without async and await...
I pass the reference object loader to the function argument (as optional) and handle it from there...