Question 11
Consider the Vue application
const Home = { template: `<div> This is home <router-view /></div>`,}
const NotFound = { template: `<div>Not Found</div>`,}
const Students = { template: `<ul><li v-for='student in students'>{{student.name}}</li></ul>`, data() { return { students: [ { id: 1, name: 'std1', course: 'mad1' }, { id: 2, name: 'std2', course: 'mad2' }, { id: 3, name: 'std3', course: 'mad1' }, ], } },}const Student = { template: `<div>Name: {{student.name}}, Course: {{student.course}}</div>`, props: ['id'], computed: { student() { return Students.data().students.find((std) => { return std.id == (this.id % 3) + 1 }) }, },}
const router = new VueRouter({ routes: [ { path: '/', component: Home, children: [ { path: '', component: Students }, { path: 'student/:id', component: Student, props: true }, { path: '*', component: NotFound }, ], }, ],})
new Vue({ el: '#app', template: `<div><router-view /></div>`, router,})Name: std1, Course: mad1
Name: std2, Course: mad2
Name: std3, Course: mad1
Not Found