8000 doc: update `setup` · dung13890/vue-function-api@4c55a58 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4c55a58

Browse files
committed
doc: update setup
1 parent 86f8ffa commit 4c55a58

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,25 @@ After installing the plugin you can use the new [function API](#API) to compose
119119

120120
A new component option, `setup()` is introduced. As the name suggests, this is the place where we use the function-based APIs to setup the logic of our component. `setup()` is called when an instance of the component is created, after props resolution. The function receives the resolved props as its first argument.
121121

122-
123-
Example:
122+
The second argument provides a `context` object which exposes a number of properties that were previously exposed on this in 2.x APIs.
124123

125124
```js
126125
const MyComponent = {
127126
props: {
128127
name: String
129128
},
130-
setup(props) {
131-
console.log(props.name)
129+
setup(props, context) {
130+
console.log(props.name);
131+
// context.attrs
132+
// context.slots
133+
// context.refs
134+
// context.emit
135+
// context.parent
136+
// context.root
132137
}
133138
}
134139
```
135140

136-
> **`this` is not available inside `setup()`.**
137-
138-
139141
## value
140142

141143
**value**(value: *`any`*): [`Wrapper`][Wrapper]

README.zh-CN.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,19 @@ Vue.use(plugin)
123123

124124
`setup()` 中不可以使用 `this` 访问当前组件实例, 我们可以通过 `setup` 的第二个参数 `context` 来访问 vue2.x API 中实例上的属性。
125125

126-
Example:
127-
128126
```js
129127
const MyComponent = {
130128
props: {
131129
name: String
132130
},
133-
setup(props) {
134-
console.log(props.name)
131+
setup(props, context) {
132+
console.log(props.name);
133+
// context.attrs
134+
// context.slots
135+
// context.refs
136+
// context.emit
137+
// context.parent
138+
// context.root
135139
}
136140
}
137141
```

0 commit comments

Comments
 (0)
0