2022-01-27

Typed events in Vue 3?

Currently I am manually casting an event:

const emit = defineEmits<{
  (e: 'update:modelValue', value: string | number): void
}>()

// [..]    

<input
  type="text"
  :value="modelValue"
  @input="emit('update:modelValue', ($event.target as // manually
HTMLInputElement).value)"                             // casted
/>

Is there any better way than this? Any way around having to cast it?

Hint: I am not using v-model here because the shown code is part of a component (on which v-model will be used then)



from Recent Questions - Stack Overflow https://ift.tt/3fXP1EG
https://ift.tt/eA8V8J

No comments:

Post a Comment