-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Description
This was originally raised in https://github.com/yyx990803/vue/issues/1173#issuecomment-139092569
Problem
v-ref
and v-el
are some special built-in feature that allow you to register a child component or a DOM node on the parent component. They are not really directives, but were presented as "literal directives" in previous versions. In 1.0.0, we are making literal directives more explicit, which also makes writing them a little more verbose (example: v-ref.literal="xxx"
).
In addition, the user needs to consult the doc to remember that v-el
registers under vm.$$
, and v-ref
registers under vm.$
. The $
and $$
are not very explicit and does not map well with the directive names.
Proposal
Rename to more explicit properties:
vm.$
->vm.$refs
vm.$$
->vm.$els
Use the arguments in the new binding syntax to mark the ref id:
<!-- child component ref, registers vm.$refs.child -->
<comp v-ref:child></comp>
<!-- elsewhere... -->
{{$refs.child.msg}}
<!-- element ref, registers vm.$els.node -->
<div v-el:node></div>
Caveats
camelCase names are converted to all lowercase when the HTML is parsed:
<comp v-ref:someThing></comp>
Gets rendered as:
<comp v-ref:something></comp>
Thus, it is necessary to use the dash-case <-> camelCase mapping for refs too (similar to props):
<comp v-ref:some-thing></comp>
{{ $refs.someThing.msg }}