how to emit a function in vue composition api code example
Example 1: how to emit a function in vue
this.$emit('myEvent')
Example 2: vue emit composition api
<template>
<div id="app" style={{ width: widthPixel, height: heightPixel }}>
dynamic window size: {width}, {height}
</div>
</template>
<script>
import { watch } from '@vue/composition-api'
export default {
setup(props, { emit }) {
const { width, height, widthPixel, heightPixel } = useWindowSize()
watch(() => {
emit('window-width-changed', width)
})
return { width, height, widthPixel, heightPixel }
}
}
</script>