VueJs: Touch after modifying selection value in child component
P粉878542459
2023-09-04 17:10:56
<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>
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.