Vue.js - define v-model with defineProps and defineModel

28 Views Asked by At

When I am creating a component that receives 2 properties, but one of them must be "two way binding" as in the example below:

<script
  setup
  lang="ts"
>
type TextFieldCompProps = {
  required?: boolean;
  modelValue: string;
}

defineProps<TextFieldCompProps>()
const modelValue = defineModel<string>({ required: true })
</script>

Is it correct to declare "modelValue" in TextFieldProps and use defineModel for this purpose?

Or the TextFieldProps must be only type TextFieldProps = { required?: boolean }

0

There are 0 best solutions below