[Vuejs]-How to set parent component data from child component in vuejs

1👍

you can use component events i.e $emit.

Below is example which will tell you how to use $emit. (https://vuejs.org/guide/components/events.html#emitting-and-listening-to-events)

Parent Component

<template>
  <ChildComponent @updateTabsValue="updateTabsValue"/>
</template>
<script>
export default {
data(){
  return {
    tabsValue: 'tabs',
  };
},
methods:{
  updateTabsValue(val){
    this.tabsValue = val;
  }
},
}
</script>

Child Component

<template>
  <button @click="$emit('updateTabsValue','newVal')"/>
</template>

Leave a comment