I have like this code in my app:
<div id="app">
<button v-if="!isLoaded && !isLoading" @click="startLoading()">Start Loading</button>
<div v-if="isLoading">Loading app...</div>
<template v-else>
<img v-show="isLoaded" ref="img" />
</template>
</div>
<script>
new Vue({
el: "#app",
data() {
return {
isLoading: false,
isLoaded: false,
}
},
mounted() {
},
methods: {
startLoading() {
this.isLoading = true;
for (let i = 1; i < 1E9; ++i) {
//Dummy load;
const a = 1;
}
this.isLoading = false;
this.isLoaded = true;
this.$refs.img.src = 'https://cdn.pixabay.com/photo/2018/07/04/11/58/xiamen-3515964__340.jpg';
}
},
})
</script>
In this code, when you click on the "Start Download" button, the message "Loading..." should appear for a while, after which the image will appear. But there is no sign "Loading". Why? Can this be fixed? If so, correct it. (It is undesirable to remove the dummy load. Imagine that we are there very intensively processing some file for the user)