search

Home  >  Q&A  >  body text

VueJs: Touch after modifying selection value in child component

<p>I'm using VueJs and I have this child component in my parent component. When the selection of the child component changes, I need to trigger a function in the parent component. </p> <p><strong>Subcomponent:</strong></p> <pre class="brush:php;toolbar:false;">watch: { selectCoin() { this.$emit("currencyType", this.selectCoin["title"]); } }</pre> <p>The child component I use inside the <strong>parent component</strong>: </p> <pre class="brush:php;toolbar:false;"><app-select-coin @coin="body.value = $event" @currencyType="body.currencyType = $event" :data="body" /></pre> <p>When the child component responds to the $emit of the parent component, I need to call this method: </p> <pre class="brush:php;toolbar:false;">methods :{ myFunction() { } }</pre>
P粉878542459P粉878542459517 days ago625

reply all(1)I'll reply

  • P粉312631645

    P粉3126316452023-09-05 09:28:14

    I successfully accomplished this by adding a function in the "v-on" of @currencyType and passing it the value received from the child component as a parameter.

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

    reply
    0
  • Cancelreply