Skip to content
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

fix(v-model): create non-existent properties as reactive #80

Merged
merged 1 commit into from Oct 5, 2019

Conversation

allex
Copy link
Contributor

@allex allex commented Sep 19, 2019

fix v-model assign non-existent properties as reactive.

<MyComponent vModel={a.b} />

to

<MyComponent model={{
  value: a.b,
  callback: $$v => {
    this.$set(a, "b", $$v); // a.b = $$v;
  }
}} />

@sodatea sodatea merged commit a075fd3 into vuejs:dev Oct 5, 2019
@vue-bot
Copy link

vue-bot commented Oct 5, 2019

Hey @allex, thank you for your time and effort spent on this PR, contributions like yours help make Vue better for everyone. Cheers! 💚

@jvbianchi
Copy link

If you use JSX inside setup, this won't be defined (as per spec) and this PR will cause errors.

@sodatea
Copy link
Member

sodatea commented Oct 13, 2019

@jvbianchi Any reproductions? Also, I think @vue/composition-api is not fully compatible with this preset anyway. Before this PR, we already transformed code like vModel={a['b']}.

@jvbianchi
Copy link

jvbianchi commented Oct 13, 2019

@sodatea here is the reproduction: https://github.com/jvbianchi/jsx-vmodel-reproduction

just change the value in the input, you will get this error:

[Vue warn]: Error in v-on handler: "TypeError: Cannot read property '$set' of undefined"

TypeError: Cannot read property '$set' of undefined

Before this PR it worked fine.

@tiepnguyen
Copy link

@jvbianchi this issue is real, I also ran into this error 2 days ago after npm update and I didn't know why until I found this PR, now all my v-model inside setup() are not working. May becus this does not exist in setup() ? I don't know but trying to roll back to 1.1.0

@jvbianchi
Copy link

jvbianchi commented Oct 15, 2019

@tiepnguyen Yes, if you rollback to a previous version, it works fine.

@sodatea Should I open a new issue?

@sodatea
Copy link
Member

sodatea commented Oct 15, 2019

We could track it in a separate issue. But I'm still thinking about whether we should support @vue/composition-api in this library. There may be many edge cases because the current implementation is heavily depended on this. Maybe this should be transformed in https://github.com/luwanquan/babel-preset-vca-jsx instead.

@jvbianchi
Copy link

@luwanquan What do you think?

@dxyqqs
Copy link

dxyqqs commented Jan 15, 2020

Hi @allex & @sodatea ,
if 'v-model' was used in the functional component, the 'this' will be null.

Cannot read property '$set' of null

e.g:
<tag vModel={parent.props}></tag>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants