You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/guide/composition-api-introduction.md
+18-23Lines changed: 18 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,7 +76,7 @@ Now that we know the **why** we can get to the **how**. To start working with th
76
76
The new `setup` component option is executed **before** the component is created, once the `props` are resolved, and serves as the entry point for composition API's.
77
77
78
78
::: warning
79
-
Because the component instance is not yet created when `setup` is executed, there is no `this`inside a `setup` option. This means, with the exception of `props`, you won't be able to access any properties declared in the component – **local state**, **computed properties** or **methods**.
79
+
Although the component instance has been created, it is not bound to `this`when the setup is executed, so `this`cannot be used in the setup, and the processing of props is also completed later, this means, with the exception of `props`, you won't be able to access any properties declared in the component – **local state**, **computed properties** or **methods**.
80
80
:::
81
81
82
82
The `setup` option should be a function that accepts `props` and `context` which we will talk about [later](composition-api-setup.html#arguments). Additionally, everything that we return from `setup` will be exposed to the rest of our component (computed properties, methods, lifecycle hooks and so on) as well as to the component's template.
@@ -91,14 +91,14 @@ export default {
91
91
props: {
92
92
user: {
93
93
type:String,
94
-
required:true
95
-
}
94
+
required:true,
95
+
},
96
96
},
97
97
setup(props) {
98
98
console.log(props) // { user: '' }
99
99
100
100
return {} // anything returned here will be available for the rest of the component
101
-
}
101
+
},
102
102
// the "rest" of the component
103
103
}
104
104
```
@@ -298,14 +298,14 @@ Whenever `counter` is modified, for example `counter.value = 5`, the watch will
298
298
exportdefault {
299
299
data() {
300
300
return {
301
-
counter:0
301
+
counter:0,
302
302
}
303
303
},
304
304
watch: {
305
305
counter(newValue, oldValue) {
306
306
console.log('The new counter value is: '+this.counter)
307
-
}
308
-
}
307
+
},
308
+
},
309
309
}
310
310
```
311
311
@@ -420,7 +420,7 @@ export default function useUserRepositories(user) {
0 commit comments