需求是,我需要点击v-for
循环出来的列表项,然后转跳到对应的UserDetail
组件,我的路由这样写,没有出现转跳,哪里写错了没?
路由:
const router = new VueRouter({
routes: [
{
path: '/user',
component: User,
name: 'user',
children: [
{ path: ':userId', component: UserDetail,name:'detail'},
]
},
{
path: '/about',
component: About,
name: about
}
]
})
User.vue:
<template>
<div v-for="(user,index) in users" @click="goDetails(index)">{{user.name}}</div>
<router-view></router-view>
</template>
<script>
export default {
data(){
return {
users: [{name:'abby'},{name:'cici'},{name:'jane'}]
}
},
methods:{
goDetails(index){
this.$router.push({
params: {userId: index}
})
}
}
}
<script>
UserDetail: