Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Vue refs works differently in template vs render function #8225

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

Closed
adalberth opened this issue May 22, 2018 · 3 comments
Closed

Vue refs works differently in template vs render function #8225

adalberth opened this issue May 22, 2018 · 3 comments

Comments

@adalberth
Copy link

Version

2.5.17-beta.0

Reproduction link

https://codepen.io/Stupid/pen/WJmgjm?editors=1010

Steps to reproduce

Create ref within template and in render function, template returns array, render function returns latest item in loop.

What is expected?

render functions should return an array of the "refs" (https://vuejs.org/v2/guide/render-function.html#v-if-and-v-for)

What is actually happening?

Of course it makes sense that the render function returns the last ref as JS should. But in vue shouldn't it return an array as the template do?

@sqal
Copy link
Contributor

sqal commented May 22, 2018

You need to add refInFor manually to the data object, here:

return createElement('li', {
  ref: 'list_a',
  refInFor: true
}, idx)

@adalberth
Copy link
Author

adalberth commented May 22, 2018

Yep, that works! Thx! Shouldn't that be in the docs?

@Igloczek
Copy link

Igloczek commented Aug 4, 2018

It's listed at the end of the data object:
https://vuejs.org/v2/guide/render-function.html#The-Data-Object-In-Depth

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

3 participants