Last active
November 26, 2021 09:02
-
-
Save JimYaaa/6dff1e22bd01970a1c85c5cddb4e2737 to your computer and use it in GitHub Desktop.
Vue Recursive Component Emit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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