Does defineModel() work with object props #10974
Replies: 2 comments 1 reply
-
It works for me. <script lang="ts" setup>
const state = reactive({
bubble: {
message: '',
files: [],
},
});
</script>
<template>
<ChatBubble v-model="state.bubble" />
</template> type BubbleChatBox = {
message: string;
files: (File & { url?: string })[];
};
const defaultModel = defineModel<BubbleChatBox>({
default: { message: '', files: [] },
}); |
Beta Was this translation helpful? Give feedback.
-
Mutating So you should replaced with a copy rather than mutate. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Examples show only usage with primitive types, how will it work with object props?
I test with the following example,
Parent.vue
Child.vue
defineModel work with object props. but i have the following question:
when chang model.value in 'Child.vue'
vue direct change the msg.value.text in 'Parent.vue'
3. defineModel for object props is suggested.
中文(translate for chinese)
当修改'Child.vue'中的model.value
vue 直接修改了 'Parent.vue' 中的msg.value.text
4. 官方是否推荐 使用defineModel绑定Object数据类型或者Array数据类型。
Beta Was this translation helpful? Give feedback.
All reactions