Using v-model with @vue/compat and configureCompat in Composition API #7862
-
I have a working Vue 3 application, it is configured with I want to create a component with a const props = defineProps<{ modelValue: string }>();
const content = computed({
get: () => props.modelValue,
set: (value) => emit("update:modelValue", value),
}); Defined as above, it won't work because const props = defineProps<{ value: string }>();
const content = computed({
get: () => props.value,
set: (value) => emit("input", value),
}); But now, TypeScript shout an error from the parent component (in which we want to pass a The solution I'm thinking about is to disable As said in the migration guide, we can configure this like so: export default {
compatConfig: {
MODE: 2,
COMPONENT_V_MODEL: false,
}
// ...
} But I'm using the Composition API with TypeScript and there is no Maybe I'm doing something wrong, any help is welcome. Thank you all. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
https://vue-macros.sxzz.moe/macros/define-model.html |
Beta Was this translation helpful? Give feedback.
-
By using a second script block. <script>
export default {
compatConfig: {
MODE: 2,
COMPONENT_V_MODEL: false,
}
}
</script>
<script setup>
const props = defineProps<{ modelValue: string }>();
const content = computed({
get: () => props.modelValue,
set: (value) => emit("update:modelValue", value),
});
</script>
`` |
Beta Was this translation helpful? Give feedback.
By using a second script block.