|
| 1 | +# Instance Properties |
| 2 | + |
| 3 | +## $data |
| 4 | + |
| 5 | +- **Type:** `Object` |
| 6 | + |
| 7 | +- **Details:** |
| 8 | + |
| 9 | + The data object that the Vue instance is observing. The Vue instance proxies access to the properties on its data object. |
| 10 | + |
| 11 | +- **See also:** [Options / Data - data](./options-data.html#data-2) |
| 12 | + |
| 13 | +## $props |
| 14 | + |
| 15 | +- **Type:** `Object` |
| 16 | + |
| 17 | +- **Details:** |
| 18 | + |
| 19 | + An object representing the current props a component has received. The Vue instance proxies access to the properties on its props object. |
| 20 | + |
| 21 | +## $el |
| 22 | + |
| 23 | +- **Type:** `any` |
| 24 | + |
| 25 | +- **Read only** |
| 26 | + |
| 27 | +- **Details:** |
| 28 | + |
| 29 | + The root DOM element that the Vue instance is managing. |
| 30 | + |
| 31 | +## $options |
| 32 | + |
| 33 | +- **Type:** `Object` |
| 34 | + |
| 35 | +- **Read only** |
| 36 | + |
| 37 | +- **Details:** |
| 38 | + |
| 39 | + The instantiation options used for the current Vue instance. This is useful when you want to include custom properties in the options: |
| 40 | + |
| 41 | + ```js |
| 42 | + const app = Vue.createApp({ |
| 43 | + customOption: 'foo', |
| 44 | + created() { |
| 45 | + console.log(this.$options.customOption) // => 'foo' |
| 46 | + } |
| 47 | + }) |
| 48 | + ``` |
| 49 | + |
| 50 | +## $parent |
| 51 | + |
| 52 | +- **Type:** `Vue instance` |
| 53 | + |
| 54 | +- **Read only** |
| 55 | + |
| 56 | +- **Details:** |
| 57 | + |
| 58 | + The parent instance, if the current instance has one. |
| 59 | + |
| 60 | +## $root |
| 61 | + |
| 62 | +- **Type:** `Vue instance` |
| 63 | + |
| 64 | +- **Read only** |
| 65 | + |
| 66 | +- **Details:** |
| 67 | + |
| 68 | + The root Vue instance of the current component tree. If the current instance has no parents this value will be itself. |
| 69 | + |
| 70 | +## $slots |
| 71 | + |
| 72 | +- **Type:** `{ [name: string]: (...args: any[]) => Array<VNode> | undefined }` |
| 73 | + |
| 74 | +- **Read only** |
| 75 | + |
| 76 | +- **Details:** |
| 77 | + |
| 78 | + Used to programmatically access content [distributed by slots](../guide/component-basics.html#content-distribution-with-slots). Each [named slot](../guide/component-slots.html#named-slots) has its own corresponding property (e.g. the contents of `v-slot:foo` will be found at `vm.$slots.foo()`). The `default` property contains either nodes not included in a named slot or contents of `v-slot:default`. |
| 79 | + |
| 80 | + Accessing `vm.$slots` is most useful when writing a component with a [render function](TODO). |
| 81 | + |
| 82 | +- **Example:** |
| 83 | + |
| 84 | + ```html |
| 85 | + <blog-post> |
| 86 | + <template v-slot:header> |
| 87 | + <h1>About Me</h1> |
| 88 | + </template> |
| 89 | + |
| 90 | + <template v-slot:default> |
| 91 | + <p> |
| 92 | + Here's some page content, which will be included in vm.$slots.default. |
| 93 | + </p> |
| 94 | + </template> |
| 95 | + |
| 96 | + <template v-slot:footer> |
| 97 | + <p>Copyright 2020 Evan You</p> |
| 98 | + </template> |
| 99 | + </blog-post> |
| 100 | + ``` |
| 101 | + |
| 102 | + ```js |
| 103 | + const app = Vue.createApp({}) |
| 104 | + |
| 105 | + app.component('blog-post', { |
| 106 | + render() { |
| 107 | + return Vue.h('div', [ |
| 108 | + Vue.h('header', this.$slots.header()), |
| 109 | + Vue.h('main', this.$slots.default()), |
| 110 | + Vue.h('footer', this.$slots.footer()) |
| 111 | + ]) |
| 112 | + } |
| 113 | + }) |
| 114 | + ``` |
| 115 | + |
| 116 | +- **See also:** |
| 117 | + - [`<slot>` Component](TODO) |
| 118 | + - [Content Distribution with Slots](../guide/component-basics.html#content-distribution-with-slots) |
| 119 | + - [Render Functions - Slots](TODO) |
| 120 | + |
| 121 | +## $refs |
| 122 | + |
| 123 | +- **Type:** `Object` |
| 124 | + |
| 125 | +- **Read only** |
| 126 | + |
| 127 | +- **Details:** |
| 128 | + |
| 129 | +An object of DOM elements and component instances, registered with [`ref` attributes](TODO). |
| 130 | + |
| 131 | +- **See also:** |
| 132 | + - [Child Component Refs](TODO:refs) |
| 133 | + - [Special Attributes - ref](TODO) |
| 134 | + |
| 135 | +## $attrs |
| 136 | + |
| 137 | +- **Type:** `Object` |
| 138 | + |
| 139 | +- **Read only** |
| 140 | + |
| 141 | +- **Details:** |
| 142 | + |
| 143 | +Contains parent-scope attribute bindings and events that are not recognized (and extracted) as component [props](./options-data.html#props) or [custom events](./options-data.html#emits). When a component doesn't have any declared props or custom events, this essentially contains all parent-scope bindings, and can be passed down to an inner component via `v-bind="$attrs"` - useful when creating higher-order components. |
| 144 | + |
| 145 | +- **See also:** |
| 146 | + - [Non-Prop Attributes](../guide/component-props.html#non-prop-attributes) |
0 commit comments