我该如何解决这个问题。
我有一个按钮,该按钮应将我链接到有关已创建对象的视图。例如
<router-link :to="{ name:DetailView,
params:{ id: detail.id}
}
@click="createDetail()> Create Detail
</router-link>
在后端请求之后设置了我的组件detail
:
detail:Detail;
createDetail(){
makeBackendCall().then(detail=>{
this.detail=detail
})
}
这是我得到的警告/错误:
[vue-router] missing param for named route "name:DetailView":
Expected "id" to match "[^\/]+?", but received ""
显然detail
组件尚未加载。有什么我想念的吗?
答案 0 :(得分:2)
您应该制作一个普通的html按钮,然后在创建后端对象后手动重定向用户(并使用css设置按钮的样式)
<button @click="createDetail()> Create Detail
</button>
createDetail(){
makeBackendCall().then(detail=>{
this.$router.push({
name: DetailView,
params: {
id: detail.id
}
})
})
}
在上面的代码中,$router
是到当前活动Vue路由器and there are also other methods you can call on it, to do differend things
答案 1 :(得分:0)
当您尝试首次渲染“ detail.id”时,这是一个常见错误。属性“ id”可能未定义。因此,您可以执行以下操作来避免发出警告:
Start-Process -FilePath $Path -ArgumentList $argumentList -NoNewWindow -Wait