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

Strange binding behaviour #4658

Closed
Rhincodon opened this issue Jan 5, 2017 · 10 comments · Fixed by #4662
Closed

Strange binding behaviour #4658

Rhincodon opened this issue Jan 5, 2017 · 10 comments · Fixed by #4662

Comments

@Rhincodon
Copy link

Rhincodon commented Jan 5, 2017

Vue.js version

2.1.7+

Reproduction Link

https://jsfiddle.net/rhinodontypicus/tvcz49bd/

Steps to reproduce

Change input value, click Button -> value rolls back.

What is Expected?

Input value must not be touched at all.

What is actually happening?

Input value rolls back to origin value.

If we remove v-bind:disabled from button, it works as needed — nothing happened.

@defcc
Copy link
Member

defcc commented Jan 5, 2017

This is an expected behavior in Vue.js 2.

When doing value changes, your app gets re-rendered, so the input value is reseted to 1. You could use v-model. I updated the fiddler here https://jsfiddle.net/tvcz49bd/1/. You also could use v-once.

@defcc defcc closed this as completed Jan 5, 2017
@Rhincodon
Copy link
Author

Rhincodon commented Jan 5, 2017

@defcc Why this behavior appeared only in Vue 2.1.7+ , not in prev releases. Is this not breaking change? Cause if you say its just how it works, why it start working like that only from release 2.1.7 specific.

@Rhincodon
Copy link
Author

Rhincodon commented Jan 5, 2017

@defcc And if you say that whole template is re-render, why if we change input to textarea, its value not rolled back like input value?

@Rhincodon
Copy link
Author

@defcc If I need submit form with ajax without bind any values to vue, I cant use vue. Is that correct?

@defcc
Copy link
Member

defcc commented Jan 5, 2017

@Rhincodon , I'll have a check on it.

@posva
Copy link
Member

posva commented Jan 5, 2017

@Rhincodon This is a very good usecase for v-once actually 🙂 (as @defcc pointed out). It's a coincidence it worked with vue. It's true that it could be optimised
If you need to send data with ajax, just put v-once on the container element if every child (+ parent) doesn't need vue. Otherwise put it for every child. So, no, it's not correct, you can absolutely use Vue for that 😄

@defcc
Copy link
Member

defcc commented Jan 5, 2017

Thanks @Rhincodon , I'll open this issue.

@defcc defcc reopened this Jan 5, 2017
@defcc
Copy link
Member

defcc commented Jan 5, 2017

In 2.1.7 static value attribute was added to dom property, which introduced the different behavior between the previous version. Related issue: #4530.

As for textarea, it's different from input element in internal implemention.

@defcc defcc added the 2.1 label Jan 5, 2017
@Rhincodon
Copy link
Author

@defcc @posva Thanks, I partially understand now. All parts of my html with not binded inputs that inside app template need to be wrapped in v-once?

@defcc
Copy link
Member

defcc commented Jan 5, 2017

In fact, Vue will do this automaticly, you don't need to keep it in mind. You could check this doc for more details: https://vuejs.org/v2/api/#v-once.

As for this issue, we will fix this case.

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 a pull request may close this issue.

3 participants