Question 15
You are given the following HTML and JavaScript code that uses Vue 2 via CDN along with Vue Router. Read the code carefully and answer the given subquestions.
app.js
const Home = { template: ` <div> <h2>Home Page</h2> <p v-if="loading">Loading data...</p> <p v-show="!loading">{{ message }}</p> <button @click="fetchData">Fetch</button> </div> `, data() { return { message: '', loading: false }; }, methods: { async fetchData() { this.loading = true; await this.simulateApiCall().then((res) => { this.message = res; this.loading = false; }); }, simulateApiCall() { return new Promise((resolve) => {
setTimeout(() => resolve("Fetched Data from API!"), 1000); }); } } }; const About = { template: '<div><h2>About Page</h2></div>' }; const router = new VueRouter({ routes: [ { path: '/home', component: Home }, { path: '/about', component: About } ]});
new Vue({ el: '#app', router});