With Vue version 3.2, if you want to emit an event from inside <script setup>
, then all you have to do is define your emits with the defineEmits()
method that is automatically available inside <script setup>
(you don’t have to import it), then you can emit the event by calling emit('myEventName', myParams)
. Here’s some sample code…
<script setup>
const emit = defineEmits(['eventA', 'eventB'])
function btnClick(params) {
emit('eventA')
emit('eventB', params)
}
</script>