Skip to content

v-el behaviour #2248

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
jbrialon opened this issue Jan 28, 2016 · 12 comments
Closed

v-el behaviour #2248

jbrialon opened this issue Jan 28, 2016 · 12 comments

Comments

@jbrialon
Copy link

Hello,

right now when we use v-el we are able to register a reference to a DOM element on its owner Vue instance’s $els object for easier access.

it could be great if it could retrieve an array of object by using v-els for example

<span v-els:msg>hello</span>
<span v-els:msg>world</span>
this.$els.msg // -> array(<span>hello</span>,<span>world</span>);
@lbineau
Copy link

lbineau commented Jan 28, 2016

@jbrialon would be a great feature ! 👍

@blake-newman
Copy link
Member

👍

@yyx990803
Copy link
Member

I don't quite get why this is useful. Any convincing use case?

@jbrialon
Copy link
Author

In my case I was animating different elements using Tweenmax and using v-el was pretty convenient then I had to use the stagger function from Tweenmax and I thought it would have been great if we could retrieve an array

that's one example of course but there would be other applications for the functionality

@cgarnier
Copy link

Yes could be great for massive animation stuff.

@AnyGong
Copy link

AnyGong commented Jan 28, 2016

@jbrialon Vue.js the v-els equivalent to document.getElementById (), which is similar to your needs, is not used document.querySelectorAll ('.msg') // -> Array (<span> hello </ span>, <span> world </ span>);
I have this idea possible? You can not achieve this requirement?

@jbrialon
Copy link
Author

@AnyGong of course but why implementing v-el if you could use document.getElementById in the first place then

@young-steveo
Copy link

It seems useful. Might I suggest this syntax:

Instead of v-els use a modifier for the standard v-el. A .list modifier would tell the directive to put the elements in an array:

<span v-el:message>hello</span> <!-- this.$els.message -->
<span v-el:messages.list>world 1</span> <!-- this.$els.messages[0] -->
<span v-el:messages.list>world 2</span><!-- this.$els.messages[1] -->

@jbrialon
Copy link
Author

jbrialon commented Feb 3, 2016

v-els was a suggestion but .list is a good idea too ! 👍

@blake-newman
Copy link
Member

I like the modifier as my preference but either will suffice.

@Gerhut
Copy link

Gerhut commented Feb 19, 2016

I have a requirement that make the window scroll to the nth row of a table rendered by v-for.

If array of v-el is supported I can wrote:

<table>
<tbody>
  <tr v-for="" v-el:row></tr>
</tbody>
</table>
exports.methods.scrollToRow = function (index) {
  this.$els.row[index].scrollIntoView()
}

But now I must make tr a component and use v-ref and get its $el

@yyx990803
Copy link
Member

I'm not convinced by the benefits of this suggestion - it introduces extra syntax on Vue's part (increases both implementation complexity and learning cost) while the same can simply be achieved with this.$el.querySelectorAll.

posva added a commit to posva/docs-next that referenced this issue Sep 29, 2020
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

8 participants