题目
下列应用push()方法实现导航的代码不正确的是()。A. this.router.push(( path: 'home' ))B. this.router.push(( path: 'home', query: { id: '2' )})C. this.router.push(( path: 'home', params: { id: '2' )})D. this.router.push(( name: 'user', params: { userId: '1' )})
下列应用push()方法实现导航的代码不正确的是()。
A. this.$router.push({ path: 'home' })
B. this.$router.push({ path: 'home', query: { id: '2' }})
C. this.$router.push({ path: 'home', params: { id: '2' }})
D. this.$router.push({ name: 'user', params: { userId: '1' }})
题目解答
答案
C. this.$router.push({ path: 'home', params: { id: '2' }})
解析
在Vue.js的路由管理中,`push()`方法用于导航到新的URL。`path`参数用于指定路径,`query`参数用于传递查询参数,而`params`参数用于传递动态参数。在Vue Router中,`params`参数应该与`name`参数一起使用,而不是与`path`参数一起使用。因此,选项C中的代码不正确,因为它试图在`path`参数中使用`params`参数。