首先:应该通过子路由实现:
{ path: '/search', component: Search, children: [ { path: ':id', component: SingerDetail } ] }
第二步:添加点击事件:
searchItem (item) { // 点击事件接收item参数,通过item的type来判断。 if (item.type === TYPE_SINGER) { const singer = new Singer({ id: item.singermid, name: item.singername }) // 这里通过singer类来创建一个singer this.$router.push({ path: `/search/${singer.id}` }) this.setSinger(singer) // 这里是通过setSinger来改变state里面的数据 } },
...mapMutations({ setSinger: 'SET_SINGER' })