As title,when I typed 'emit(update:${propsName}, evt);' in CustomInput component,the error goes 'Argument of type 'update:${string}' is not assignable to parameter of type '"update:modelValue" | "update:lastName"'.'
Any help would be much appreciated!
//App.js
<script setup lang="ts">
import { ref } from "vue";
import CustomInputVue from "./components/CustomInput.vue";
let firstName = ref("");
let lastName = ref("");
</script>
<template>
<CustomInputVue
v-model.no-whiteSpace="firstName"
v-model:lastName="lastName"
/>
</template>
//CustomInput.vue
<script setup lang="ts">
const props = defineProps({
modelValue: {
type: String,
required: false,
},
lastName: {
type: String,
required: false,
},
modelModifiers: {
type: Object as any,
required: false,
},
});
const emit = defineEmits(["update:modelValue", "update:lastName"]);
const emitValue = (propsName: string, e: Event) => {
let evt = (e.target as HTMLInputElement).value;
if (props.modelModifiers["no-whiteSpace"]) {
evt = evt.replace(/\s/g, "");
}
emit(`update:${propsName}`, evt); =>
};
</script>
<template>
<label class="block text-gray-700 text-sm font-bold mb-2" for="firstName">
First Name
</label>
<input
class="appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none mb-4"
id="firstName"
type="text"
placeholder="First Name"
:value="modelValue"
@input="emitValue('modelValue', $event)"
/>
<label class="block text-gray-700 text-sm font-bold mb-2" for="lastName">
Last Name
</label>
<input
class="appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none"
id="lastName"
type="text"
placeholder="Last Name"
:value="lastName"
@input="$emit('update:lastName', ($event.target as HTMLFormElement).value)"
/>
</template>
<style scoped></style>