# Special Attributes
number | string
keyspecial attribute is primarily used as a hint for Vue's virtual DOM algorithm to identify VNodes when diffing the new list of nodes against the old list. Without keys, Vue uses an algorithm that minimizes element movement and tries to patch/reuse elements of the same type in-place as much as possible. With keys, it will reorder elements based on the order change of keys, and elements with keys that are no longer present will always be removed/destroyed.
Children of the same common parent must have unique keys. Duplicate keys will cause render errors.
The most common use case is combined with
<ul> <li v-for="item in items" :key="item.id">...</li> </ul>1
It can also be used to force replacement of an element/component instead of reusing it. This can be useful when you want to:
- Properly trigger lifecycle hooks of a component
- Trigger transitions
<transition> <span :key="text"> </span> </transition>1
<span>will always be replaced instead of patched, so a transition will be triggered.
string | Function
refis used to register a reference to an element or a child component. The reference will be registered under the parent component's
$refsobject. If used on a plain DOM element, the reference will be that element; if used on a child component, the reference will be component instance:
<!-- vm.$refs.p will be the DOM node --> <p ref="p">hello</p> <!-- vm.$refs.child will be the child component instance --> <child-component ref="child"></child-component> <!-- When bound dynamically, we can define ref as a callback function, passing the element or component instance explicitly --> <child-component :ref="(el) => child = el"></child-component>1
An important note about the ref registration timing: because the refs themselves are created as a result of the render function, you cannot access them on the initial render - they don't exist yet!
$refsis also non-reactive, therefore you should not attempt to use it in templates for data-binding.
See also: Child Component Refs
string | Object (component’s options object)
Used for dynamic components.
<!-- component changes when currentView changes --> <component :is="currentView"></component>