Question 3
Consider the following Vue application with javascript file “app.js” and markup file “index.html”.
index.html:
<body> <div id="app"></div></body>app.js:
const Category = { template: `<div>{{$route.params.name}}<router-view></router-view></div> `,}
const Error = { template: `<div><slot> Page Not Found </slot></div>`,}const Product = { template: ` <div> <div v-if='filteredProducts.length > 0'> <div v-for='product in filteredProducts'> Name: {{product.name}}, Price: {{product.price}} </div> </div> <Error v-else> No {{keyword}} Found </Error> </div>`, data() { return { keyword: this.$route.params.name, products: [ { category: 'Mobile', name: 'Samsung', price: '10K' }, { category: 'Mobile', name: 'Apple', price: '50K' }, { category: 'Laptop', name: 'Lenovo', price: '70K' }, ], } }, computed: { filteredProducts() { return this.products.filter( (product) => product.category.toLowerCase() == this.keyword.toLowerCase() ) }, }, components: { Error, },}const router = new VueRouter({ routes: [ { path: '/category/:name', component: Category, children: [{ path: 'product', component: Product }], }, { path: '*', component: Error }, ],})
new Vue({ el: '#app', template: '<div><router-view /></div>', router,})Suppose the application is running on “http://localhost:8080”. What will be rendered by the browser for the URL “http://localhost:8080/#/”?