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

Skip to content

same ref name in multiple item do not create array in this.$refs when in render function #4035

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
baiyaaaaa opened this issue Oct 26, 2016 · 5 comments

Comments

@baiyaaaaa
Copy link

Vue.js version

2.0.3

Reproduction Link

https://jsfiddle.net/WhiteCusp/gmve9d3p/35/

Steps to reproduce

What is Expected?

this.$refs.a should be a dom node list

What is actually happening?

this.$refs.a is a single dom

@posva
Copy link
Member

posva commented Oct 28, 2016

This is working as expected, v-ref creates an array with v-for loops. I see how this could be useful for form elements or any other element of different nature that needs the same function to be applied. However, it's something you can already achieve manually by specifying different references to different elements.

@baiyaaaaa baiyaaaaa changed the title same ref name in multiple item do not create list in this.$refs when in render function same ref name in multiple item do not create array in this.$refs when in render function Oct 30, 2016
@baiyaaaaa
Copy link
Author

but my example abrove do not creates an array, because is in render function. it working as expected only in with v-for loop. so how can i achieve that in render function?

@defcc
Copy link
Member

defcc commented Oct 30, 2016

add a refInFor attribute , https://jsfiddle.net/defcc/gmve9d3p/43/

  render(createElement) {
    return createElement('ul', [
      createElement('li', { ref: 'a', refInFor: true }, 'a'),
      createElement('li', { ref: 'a', refInFor: true  }, 'a'),
      createElement('li', { ref: 'a', refInFor: true  }, 'a'),
      createElement('li', { ref: 'a', refInFor: true  }, 'a')
    ]);
  }

@baiyaaaaa
Copy link
Author

Thanks @defcc , it work well

@LeonardoRick
Copy link

@defcc Is there a way to do that using the template syntax?

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

No branches or pull requests

4 participants