【问题标题】:Trigger a function after modify select value in children component - VueJs修改子组件中的选择值后触发函数 - VueJs
【发布时间】:2021-11-23 19:47:25
【问题描述】:

我正在使用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() {

   }
}

【问题讨论】:

    标签: vue.js vue-component vue-props


    【解决方案1】:

    我设法通过在@currencyType 的“v-on”中添加函数,并将我从“$emit”中的子项收到的值作为参数传递来做到这一点。:

    <app-select-coin
      @coin="body.value = $event"
      @currencyType="myFunction(body.currencyType = $event)"
      :data="body"
    />
    
    methods :{
       myFunction(ct) {
    
       }
    }
    

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2017-06-11
    • 1970-01-01
    • 2020-09-02
    • 2019-05-05
    • 2013-12-13
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 2021-01-12
    相关资源
    最近更新 更多