I wanted to run 2 functions simultaneously in VUE. One function will be called when component is mounted and it will be running every 10 seconds. The other function will start executing when we click on the button. Now my problem is when I click the button the function start executing and the first function will not be called till this function completed its execution.
<template>
<div>
<select v-model="file_id" class="form-control" id="">
<option v-for="(file, index) in files" :value="file.value" :key="index">
{{ file.label }}
</option>
</select>
<button class="btn btn-success" @click="handleFileUpload">Import</button>
</div>
</template>
<script>
export default {
data() {
return {
files: [],
};
},
mounted() {
this.upload_status = setInterval(() => {
this.getUploadedStatus();
}, 5000);
},
methods: {
handleFileUpload() {
//it will start executing when we click the button (need to call API)
axios.post();
},
getUploadedStatus() {
//it has to run every 10 seconds (Need to call API)
axios.get();
},
beforeDestroy() {
clearInterval(this.upload_status);
},
},
};
</script>