Use Options API to handle signals emitted by vue 3
P粉994092873
P粉994092873 2023-12-31 23:58:22
0
1
468

Is there a way to enter emissions in the vue 3 Options API similar to the Composition API? According to the combination (documentation):

<script setup lang="ts">
// type-based
const emit = defineEmits<{
  (e: 'change', id: number): void
  (e: 'update', value: string): void
}>()
</script>

But for the options API we only have payload validation (documentation):

emits: {
    addBook(payload: { bookName: string }) {
      // perform runtime validation
      return payload.bookName.length > 0
    }
  }

So if we don't need validation, eslint will treat the parameter as unused:

emits: {
    change: (id: number) => true // 'id' is defined but never used
}


P粉994092873
P粉994092873

reply all(1)
P粉811349112

Add ignore comment to suppress warning:

// eslint-disable-next-line no-unused-vars @typescript-eslint/no-unused-vars
change: (id: number) => true

Or perform simple verification on id:

change: (id: number) => typeof id === 'number'
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template