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

[2.0.0-rc.1] v-for and ref: $refs not reactive anymore? #3467

Closed
WolfgangFellger opened this issue Aug 17, 2016 · 3 comments
Closed

[2.0.0-rc.1] v-for and ref: $refs not reactive anymore? #3467

WolfgangFellger opened this issue Aug 17, 2016 · 3 comments

Comments

@WolfgangFellger
Copy link

In 2.0.0-rc.1, a construct like

<p>Count: {{$refs.components && $refs.components.length}}</p>
<sub-component v-for="item in items" ref="components">

is not working anymore (count stays at initial value, even if items and thus component count is changed). In v1, arrays of $refs would reactively update.

I am not sure if this is a bug or a feature, but #2873 does not seem to mention it.

@yyx990803
Copy link
Member

yyx990803 commented Aug 17, 2016

This is intended - the reason is that $refs are now registered/updated during the render process itself. It's not recommended to rely on $refs in templates as they are intended only for programmatic access in JavaScript.

I've updated #2873 to include this.

@toabi
Copy link

toabi commented Aug 19, 2016

@yyx990803 does this mean that using this.$refs.* in computed properties will also stop working in v2 or is it just the use in templates? Do I have to solve all this with custom events?

I currently pass validation results from children to the parent like this.

@FTAndy
Copy link

FTAndy commented May 4, 2017

you can use this.$forceUpdate() and setTimeout to rerender the view when you update the data and find that $refs not reactively update.

this.fetchSomeShit()
.then((data) => {
  this.data = data
  setTimeout(() => {
    this.$forceUpdate()
  })
})

use setTimeout to ensure the data has been given in what they say the vue taskqueue

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

No branches or pull requests

4 participants