将$ router.push用于使用props vue-router的组件时重定向错误

时间:2017-06-13 10:06:00

标签: javascript frameworks vuejs2 vue-router

我遇到了vue-router的问题,尝试使用$ router.push和props从合成器重定向到另一个。 这是代码:

this.$router.push({path: '/badges/search', query: {filter: item.tag_id}})

在路线定义中:

{ path: '/badges',
    name: 'Badges',
    component: require('./components/pages/Badges.vue'),
    beforeEnter: requireAuth,
    children: [{
        path: 'search',
        name: 'Badge-id',
        components: require('./components/pages/Badges.vue'),
        props: (route) => ({filter: route.query.filter})
   }]
}

最后,这是我得到的错误:

vue-router.esm.js:1697 TypeError: Cannot read property '_c' of undefined
at render (http://localhost:8080/app.js:27823:91)
at http://localhost:8080/app.js:30450:17
at http://localhost:8080/app.js:30477:66
at Array.map (native)
at http://localhost:8080/app.js:30477:38
at Array.map (native)
at flatMapComponents (http://localhost:8080/app.js:30476:26)
at http://localhost:8080/app.js:30415:5
at iterator (http://localhost:8080/app.js:30220:7)
at step (http://localhost:8080/app.js:30103:9)

有人知道我为什么会收到此错误吗?此外,尝试在创建的方法中的新组件(徽章)中记录“this”对象,它从未与“undefined”不同,即使使用while循环(我得到它无限)

非常感谢您的帮助!

1 个答案:

答案 0 :(得分:-1)

使用params发送道具:

this。$ router.push({path:'/ badges / search',params:{filter:item.tag_id}})