[Vuejs]-Open popup in parent component while having a click in the child component

0👍

Try this out:

Child Component:

<template>
    <div>
        <button @click="openPopup(true)">Open</button>
    </div>
</template>


<script>
// ...

export default {
  // ...
  methods: {
    openPopup(flag) {
      this.$emit("openPopupInParent", flag);
    }
  }
};
</script>

Parent Component:

<template>
    <div>
        <popup v-show="isShown" @openPopupInParent="showPopup"></popup>
    </div>
</template>

<script>
// ...

export default {
  // ...
  methods: {
    showPopup(flag) {
      this.isShown = flag
    }
  }
};
</script>

Leave a comment