Does defineModel() work with object props #10974
Unanswered
Jack8450
asked this question in
Help/Questions
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.
1 reply
-
Mutating So you should replaced with a copy rather than mutate. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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