Skip to content

Instantly share code, notes, and snippets.

@JimYaaa
Last active November 26, 2021 09:02
Show Gist options
  • Save JimYaaa/6dff1e22bd01970a1c85c5cddb4e2737 to your computer and use it in GitHub Desktop.
Save JimYaaa/6dff1e22bd01970a1c85c5cddb4e2737 to your computer and use it in GitHub Desktop.
Vue Recursive Component Emit
// Parent Component
<template>
<div>
<parent-recursive-component @recursiveEmit="recursiveEmit" />
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import ParentRecursiveComponent from './RecursiveComponent'
export default defineComponent({
name: 'Parent',
components: {
ParentRecursiveComponent
},
setup () {
const recursiveEmit = () => {
console.log('recursiveEmit!!!')
}
return {
recursiveEmit
}
}
})
</script>
// RecursiveComponent
<template>
<div class="recursive-component">
<button @click="$emit('recursiveEmit')">CLICK</button>
<recursive-component @recursiveEmit="$emit('recursiveEmit')" />
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
name: 'RecursiveComponent',
emits: ['recursiveEmit'],
setup () {
return {}
}
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment