Proposal: propsToModels() #725
Vasile-Peste
started this conversation in
General
Replies: 3 comments 17 replies
-
It seems that you are looking for |
Beta Was this translation helpful? Give feedback.
0 replies
-
<script setup>
import GrandChild from "./GrandChild.vue";
const model = defineModel();
</script>
<template>
<div>
<h3>Component</h3>
a: <GrandChild v-model="model.a" /><br />
b: <GrandChild v-model="model.b" />
</div>
</template> This doesn't trigger the emit and actually mutates the prop |
Beta Was this translation helpful? Give feedback.
13 replies
-
It seems that you need https://vueuse.org/core/useVModels/ |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The idea is that
defineProps()
should actually return a mutable copy of the actual props, with listeners on them automatically emitting when the props copies are modified or when the original props are modified.The API would be something like
propsToModels()
This is a rough implementation and can be improved a lot
This solves the issue and need of having to create a local copy of the prop and listening to its mutations in order to update the real prop. It's particularly useful when dealing with nested v-model props and when props are objects.
An example
Now
workspace
can be deeply used with v-model by child components and so on. Mutatingworkspace
will trigger an emit which will update the realworkspace
prop. If theworkspace
prop is mutated by parent or other component, the local copy will be updated too and remain mutable.Beta Was this translation helpful? Give feedback.
All reactions