I have the following code snippet in my application:
<div id="app">
<button v-if="!isPrepared && !isLoading" @click="startLoading()">Start Loading</button>
<div v-if="isLoading">Loading content...</div>
<template v-else>
<img v-show="isPrepared" ref="image" />
</template>
</div>
<script>
new Vue({
el: "#app",
data() {
return {
isLoading: false,
isPrepared: false,
}
},
mounted() {
},
methods: {
startLoading() {
this.isLoading = true;
for (let i = 1; i < 1E9; ++i) {
//Simulated loading process;
const a = 1;
}
this.isLoading = false;
this.isPrepared = true;
this.$refs.image.src = 'https://cdn.pixabay.com/photo/2018/07/04/11/58/xiamen-3515964__340.jpg';
}
},
})
</script>
When clicking on the "Start Loading" button in this code, the message "Loading..." should briefly display before the image appears. However, there seems to be an issue as the loading message does not appear. Can you identify what's causing this and suggest a fix? It's important to maintain the simulated load for user experience purposes.