|
33 | 33 |
|
34 | 34 | ## ref
|
35 | 35 |
|
36 |
| -- **Expects:** `string` |
| 36 | +- **Expects:** `string | Function` |
37 | 37 |
|
38 | 38 | `ref` is used to register a reference to an element or a child component. The reference will be registered under the parent component's `$refs` object. 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:
|
39 | 39 |
|
|
43 | 43 |
|
44 | 44 | <!-- vm.$refs.child will be the child component instance -->
|
45 | 45 | <child-component ref="child"></child-component>
|
| 46 | + |
| 47 | + <!-- When bound dynamically, we can define ref as a callback function, passing the element or component instance explicitly --> |
| 48 | + <child-component :ref="(el) => child = el"></child-component> |
46 | 49 | ```
|
47 | 50 |
|
48 |
| - When used on elements/components with `v-for`, the registered reference will be an Array containing DOM nodes or component instances. |
| 51 | +When used on elements/components with `v-for`, the registered reference will be an Array containing DOM nodes or component instances. |
49 | 52 |
|
50 |
| - 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! `$refs` is also non-reactive, therefore you should not attempt to use it in templates for data-binding. |
| 53 | +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! `$refs` is also non-reactive, therefore you should not attempt to use it in templates for data-binding. |
51 | 54 |
|
52 | 55 | - **See also:** [Child Component Refs](../guide/component-template-refs.html)
|
53 | 56 |
|
54 | 57 | ## is
|
55 | 58 |
|
56 | 59 | - **Expects:** `string | Object (component’s options object)`
|
57 | 60 |
|
58 |
| - Used for [dynamic components](../guide/component-dynamic-async.html). |
| 61 | +Used for [dynamic components](../guide/component-dynamic-async.html). |
59 | 62 |
|
60 |
| - For example: |
| 63 | +For example: |
61 | 64 |
|
62 |
| - ```html |
63 |
| - <!-- component changes when currentView changes --> |
64 |
| - <component :is="currentView"></component> |
| 65 | +```html |
| 66 | +<!-- component changes when currentView changes --> |
| 67 | +<component :is="currentView"></component> |
65 | 68 |
|
66 |
| - For detailed usage, follow the links in the description above. |
67 |
| - ``` |
| 69 | +For detailed usage, follow the links in the description above. |
| 70 | +``` |
68 | 71 |
|
69 | 72 | - **See also:**
|
70 | 73 | - [Dynamic Components](../guide/component-dynamic-async.html)
|
|
0 commit comments