methods - vue2 call a parent function using $emit from component -
i'm trying call parent methods child component, seems not working.. here code:
index.html
<div class="percorso"v-on:removeall="pathlengthtozero()"> </div>
component
vue.component('lista-percorso', { template:` <div class="col-lg-2 col-xs-2"> <div class="removeall pull-right" v-on:click="removeall()"></div> </div>`, methods:{ removeall : function(){ this.listaselezionati = []; this.$emit('removeall'); } }
parent method
pathlengthtozero : function(){ il_tuo_percorso = ['']; }
seems "pathlengthtozero" not called on emit correct way use it?
you need put v-on:removeall="pathlengthtozero"
component <lista-percorso>
below,
<lista-percorso v-on:removeall="pathlengthtozero"></lista-percorso>
and this.$emit
able fire parent method.
sample demo:
vue.component('lista-percorso', { template:` <div class="col-lg-2 col-xs-2"> <div class="removeall pull-right" v-on:click="removeall()">xxxxxxxxxx</div> </div>`, methods:{ removeall : function(){ this.listaselezionati = []; this.$emit('removeall'); } } }) var app = new vue({ el: '#app', methods:{ pathlengthtozero : function(){ alert('hello'); il_tuo_percorso = ['']; } } });
<script src="https://unpkg.com/vue"></script> <div id="app"> <div class="percorso" ></div> <lista-percorso v-on:removeall="pathlengthtozero"></lista-percorso> </div>
Comments
Post a Comment