在子组件中修改 select 值后触发函数 - VueJs
Trigger a function after modify select value in children component - VueJs
我正在使用 VueJs,我的父组件中有这个子组件,当检测到子组件的 select 发生变化时,我需要在父组件中触发一个函数。
子组件:
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”中的children 接收到的值作为参数传递来做到这一点。 :
<app-select-coin
@coin="body.value = $event"
@currencyType="myFunction(body.currencyType = $event)"
:data="body"
/>
methods :{
myFunction(ct) {
}
}
我正在使用 VueJs,我的父组件中有这个子组件,当检测到子组件的 select 发生变化时,我需要在父组件中触发一个函数。
子组件:
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”中的children 接收到的值作为参数传递来做到这一点。 :
<app-select-coin
@coin="body.value = $event"
@currencyType="myFunction(body.currencyType = $event)"
:data="body"
/>
methods :{
myFunction(ct) {
}
}