-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
[bug] a custom component v-model bug #4152
Comments
Technically, this is expected behavior. Due to the way templates are compiled into render functions in 2.0, you are essentially passing down a fresh array every time the parent component re-renders, thus triggering the child's props to be considered "changed", and finally causing computed property to be computed again. This only happens if you use inline literal values for props in the template. If you do what @defcc suggested, there would be no re-calculation because If the prop is always static (i.e. you only care about the initial value, OR you intend to mutate the prop), you can set it as a local data variable in Finally - apart from the computed being called / child re-render, the UX behavior is correct. The only downside is probably some unnecessary computation, but in practice, this is fairly cheap and I wouldn't worry too much about it unless it ends up causing noticeable performance issues. |
Tested in all 2.0.x versions.
https://jsfiddle.net/2x50quv8/
When custom component is bind with
v-model
, computed properties will be called every time when value changed.Open the jsfiddle link, click on
a, b, c
, the console will printhello
on every click.Even worse, if you text in the input, which has no relationship with the
haha-test
component, thehaha-test
component would still echohello
in console.log.But if you don't
v-model
the tag, there will be no console.log.The text was updated successfully, but these errors were encountered: