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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -