this.router.push undifind push
时间: 2023-08-23 14:16:18 浏览: 48
问题: this.router.push undefined push回答: 出现这个错误是因为在代码中将路由对象写成了this.router而不是this.$router。正确的写法应该是this.$router.push。例如,你可以使用this.$router.push({name: 'newdetails', parms: {id: id}})来进行路由跳转。另外,还有一个相关的错误是在路由链接中将属性to写成了path,正确的写法是to。例如,你可以使用<router-link :to="{path: '/newdetails', query: {getNewsId: o.id}}">{{00}}</router-link>来生成带有查询参数的路由链接。如果你在跳转后需要接收参数,可以在目标组件的mounted生命周期钩子中通过this.$route.query来访问参数。例如,你可以在mounted()中使用console.log(this.$route.query.eventsId)来打印出参数的值。希望这些解释能够帮助你解决问题。
相关问题
this.$router.push
this.$router.push方法可以通过query和params两种方式传递参数。
1. 通过query方式传递参数,可以在方法中使用query属性和键值对的形式传递参数,例如:this.$router.push({ path:'/xxx', query:{ idname:id } }),接收时可以使用this.$route.query.idname获取参数值。
2. 通过params方式传递参数,需要在路由配置中设置name属性,然后在方法中使用name属性和params属性传递参数,例如:this.$router.push({ name:'路径名称', params:{ idname:id } }),接收时可以使用this.$route.params.idname获取参数值。
--相关问题--:
this.$router.push 用法
this.$router.push是Vue.js路由器的方法,用于进行页面的导航。它可以接受不同的参数来指定导航目标。
1. 当参数为字符串时,代表目标路径。例如:
this.$router.push('/home/first')
2. 当参数为对象时,可以使用path字段指定目标路径,也可以使用name字段指定命名的路由。例如:
this.$router.push({ path: '/home/first' })
this.$router.push({ name: 'home', params: { myid: id } })
3. 当需要传递查询参数时,可以使用query字段。例如:
this.$router.push({ path: '/backend/order', query: { selected: "2" } })
需要注意的是,this.$router.push方法会将新的页面压入路由栈中,这意味着用户可以通过后退按钮返回到之前的页面。