我对道具的理解可能有误,但我似乎无法将道具传递给组件并检索其值,因为它始终是未定义的。
路线:
{
path: '/account/:username',
name: 'acccount',
component: Account
},
指向组件的路由器链接:
<router-link class="btn btn-warning margin-bottom-20" :to="{ name: 'acccount', params: {username: user.username}}">Edit</router-link>
组件:
export default {
name: 'account',
props: ['username'],
computed: {
user() {
return this.$store.getters.getUser(this.username);
}
}
}
我的/ accounts视图成功更改为/ account / {username}但是在组件上,值this.username只返回undefined。
答案 0 :(得分:0)
更新您的路线:
{
path: '/account/:username',
name: 'acccount',
component: Account
}
要:
{
path: '/account/:username',
name: 'acccount',
component: Account,
props: true
}