vue.js - Vuejs 路由器监听事件
问题描述
我有一个组件,其中道具通过路线传递(https://router.vuejs.org/guide/essentials/passing-props.html)。我的问题是如何监听组件发出的事件,以便改变从路由传递的道具?
在我的路线中,我有类似的东西
...
{
path: "details/:id?",
name: "booking.details",
component: BookingDetails,
props: true
}
...
在组件内部我有一个道具
...
props: {
invoice: {
type: Object,
required: false,
default: () => ({})
}
},
...
methods: {
save () {
this.$emit('reset-invoice') // where do I capture this event
}
}
...
解决方案
如果我正确理解了您的问题,听力部分将是<router-view>
,所以:
<router-view @reset-invoice="resetInvoice"></router-view>
无论在哪个组件中呈现此路由器视图:
{
methods: {
resetInvoice() {
// ...
}
}
}
推荐阅读
- c# - 在继承的 IHostedService 类中使用 Entity Framework Core db 上下文时缺少方法
- hadoop - 无法在 Hive 中为 JSON 文件插入数据
- reactjs - 导入图片 webpack,reactjs + typescript
- css - React-Native:在 WebView 中加载外部 CSS 文件
- scala - spark SQL中列数据(字符串数据类型)的多级排序
- c# - 模拟控制器对象方法在 Result 中返回 Null 值
- java - Spring Boot 2,如何在 ProviderManager 中设置 eraseCredentialsAfterAuthentication false
- javascript - 修复 CORB(跨源读取阻塞)
- javascript - 为什么在运行 npm test 时选择了错误的 Immutable.js Map factory 函数?
- ios - 将项目从 swift 4 转换为 swift 5 时,“ViewController”类型的值错误没有成员“keyboardDidShow(notification:)”