vue.js - 修改子组件中的选择值后触发函数 - VueJs
问题描述
我正在使用 VueJs,并且我的父组件中有这个子组件,当检测到子组件的选择发生变化时,我需要在父组件中触发一个函数。
子组件:
watch: {
selectCoin() {
this.$emit("currencyType", this.selectCoin["title"]);
}
}
我的父亲组件中的子组件:
<app-select-coin
@coin="body.value = $event"
@currencyType="body.currencyType = $event"
:data="body"
/>
当子组件响应父组件的 $emit 时,我需要调用此方法:
methods :{
myFunction() {
}
}
解决方案
我设法通过在@currencyType 的“v-on”中添加函数,并将我从“$emit”中的子项收到的值作为参数传递来做到这一点。:
<app-select-coin
@coin="body.value = $event"
@currencyType="myFunction(body.currencyType = $event)"
:data="body"
/>
methods :{
myFunction(ct) {
}
}
推荐阅读
- php - 发送邮件时在视图文件中显示数据
- javascript - NodeJS 错误“不能在模块外使用 import 语句”
- c# - 没有适用于 MVC 3 的 Sustainsys.Saml2?有没有其他选择?
- graph - 图数据库中的建模时间
- python - 这些功能是如何实现的?
- powershell - Powershell远程:具有嵌套函数的函数
- java - 为什么 apache http 客户端比 java 中的 URL.openConnection 慢 2 倍?
- mysql - 如何在存在时选择列的值
- android - Room:错误:不确定如何将 Cursor 转换为此方法的返回类型(void)
- c++ - 将 bmp 文件加载到 TSpeedButton