-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Moving v-bind.sync to the v-model API #8
Comments
Should we consider renaming the |
@posva I like that idea a lot! 🙂 It'd make component events more consistent and would actually solve a problem we currently have with transparent wrapper components. I just created a new issue to explore this further. |
May I have a question about IMO, both So I'd like to make sure in v3.0 whether the value pass to the Thanks. |
This is where we decided to bring Here are some potential problems I can think of: With the current syntax being
|
@Justineo That's a fair point. I think everywhere else that we have a directive with an optional argument, the lack of arguments is used to spread an object. Though I don't think this will actually cause much confusion in practice, since So I'm still in favor of option 2. What do you think? |
Not quite sure about it…it also disables usage like |
Good point. Though the use case is relatively rare, I agree we should handle it. Maybe a modifier like |
So how could we bind an event named |
I have another idea. Not quite sure it's good enough, but just an idea. 😅 class Foo extends Vue {
props,
data,
model() {
return {
value, ...others
}
},
...
} In another word, because the update event must be defined in the component to make sense. So maybe it's good to define model/models internal, not external as a syntax sugar only. When we return a member in Thanks. |
I don't see why we couldn't make it valid, if it isn't already. 🙂 I don't think we currently allow for multiples arguments on a directive, do we?
I don't think I fully understand what you're suggesting. Would you mind providing a more complete example to demonstrate the use case? |
Update: Found that syntax like
Well, I have realized that's not a good idea. But give an explanation here. I have written many custom components which support <template>
<input :value="localValue" @input="handle" />
</template>
<script>
export default {
props: ['value'],
data() {
return { localValue: this.value }
},
watch: {
value(val) { this.localValue = val }
},
methods: {
handle(event) {
let val = $event.target.value
// do some validations/transformations
this.setValue(val)
},
otherActions() {
// do sth.
this.setValue(...)
},
setValue(val) {
this.localValue = val
this.$emit('input', val)
}
}
}
</script> So I have a thought to simplifiy that maybe like: <template>
<input :value="localValue" @input="handle" />
</template>
<script>
export default {
// or `model: { value: { type: String, default: xxx }},`
// or `props: { value: { ..., model: true }}`
model: ['value'],
methods: {
handle(event) {
let val = $event.target.value
// do some validations/transformations
this.setValue(val)
},
otherActions() {
// do sth.
this.setValue(...)
},
}
}
</script> It supplies a data named and actually the code below also works the same: <template>
<input :value="localValue" @input="handle" />
</template>
<script>
const mixinModel = {
data() {
return { localValue: this.value }
},
watch: {
value(val) { this.localValue = val }
},
methods: {
setValue(val) {
this.localValue = val
this.$emit('input', val)
}
}
}
export default {
mixins: [mixinModel],
props: ['value'],
methods: {
handle(event) {
let val = $event.target.value
// do some validations/transformations
this.setValue(val)
},
otherActions() {
// do sth.
this.setValue(...)
},
}
}
</script> |
Just linking this comment here for reference (implementation details) #9 (comment) |
@chrisvfritz I'm starting to prepare for moving things we are discussing here to public RFCs. Do you want to champion this one? |
@yyx990803 Happy to. 🙂 Filling out the RFC now. |
This is now a public RFC, so further discussion should happen there. @Justineo Your thoughts on the best compromise for spreading an object would be especially welcome. 🙂 |
Closing in favor of the public RFC. |
@yyx990803 I've seen
v-bind.sync
cause quite a bit of confusion in Vue 2, as users expect it to be able to use expressions like withv-bind
(despite whatever we put in the docs). The explanation I've had the best success with is:Which brings me to the question: if it helps to tell users not to think of
v-bind.sync
likev-bind
, but rather to think about it likev-model
, should it be part of thev-model
API instead? For example, instead of:Perhaps a more intuitive syntax would be:
As a bonus, a change like this would be very easy to flag with the migration helper and fix with find-and-replace.
Thoughts?
The text was updated successfully, but these errors were encountered: