[Vuejs]-Executing child (component) function from the parent component

3👍

If you want to call a method defined on a child component from the parent component, you’ll have to get a reference to the child component and call its method directly:

<i v-on:click="$refs.map.change_map_data()">change markers</i>
<g-map v-bind:map_data="init_data.map" ref="map"></g-map>

If you’re generating a dynamic number of maps, then you’ll need to do something like this:

<div v-for="map, i of maps">
  <i v-on:click="$refs.map[i].change_map_data()">change markers</i>
  <g-map v-bind:map_data="map" ref="map"></g-map>
</div>

Leave a comment