javascript - Vue路由器 - 命名路由缺少参数
问题描述
我怎么解决这个问题。
我有一个按钮,可以将我链接到有关我创建的对象的视图。例如
<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
组件尚未加载。有什么我想念的吗?
解决方案
您应该制作一个普通的 html 按钮,然后在制作后端对象后手动重定向用户(并使用 css 设置按钮样式)
<button @click="createDetail()"> Create Detail
</button>
createDetail(){
makeBackendCall().then(detail=>{
this.$router.push({
name: DetailView,
params: {
id: detail.id
}
})
})
}
在上面的代码中,$router
是一个指向当前活动的 Vue 路由器的链接,还有其他方法可以调用它,做不同的事情
推荐阅读
- c++ - C++11/14/17,GCC 7 与 GCC 8:朋友类模板的名称查找
- r - 向导航栏页面添加第二个选项卡时,我再也看不到数据了
- list - 连接列表并将结果返回到第一个参数
- jsf - 如何使用 IceFaces/JSF 打印图表
- css - 使用 CSS Grid 时如何使内容居中并使背景覆盖整列?
- model-view-controller - 如何在 mvc 5 中对视图模型列表进行客户端验证?
- javascript - 根据链接(或复选框)单击隐藏/显示复选框字段
- express - Express Route 中的可变参数
- spring-boot - Spring Boot:如何正确地将错误日志发送到 GCP 上的 Stackdriver
- html - 我可以在 HTML 中用零填充数字吗?