Skip to content

Commit 53dc21c

Browse files
committed
The description of this in setup is inconsistent with the source code
1 parent 6730d26 commit 53dc21c

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

src/guide/composition-api-introduction.md

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Now that we know the **why** we can get to the **how**. To start working with th
7676
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.
7777

7878
::: 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**.
8080
:::
8181

8282
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 {
9191
props: {
9292
user: {
9393
type: String,
94-
required: true
95-
}
94+
required: true,
95+
},
9696
},
9797
setup(props) {
9898
console.log(props) // { user: '' }
9999

100100
return {} // anything returned here will be available for the rest of the component
101-
}
101+
},
102102
// the "rest" of the component
103103
}
104104
```
@@ -298,14 +298,14 @@ Whenever `counter` is modified, for example `counter.value = 5`, the watch will
298298
export default {
299299
data() {
300300
return {
301-
counter: 0
301+
counter: 0,
302302
}
303303
},
304304
watch: {
305305
counter(newValue, oldValue) {
306306
console.log('The new counter value is: ' + this.counter)
307-
}
308-
}
307+
},
308+
},
309309
}
310310
```
311311

@@ -420,7 +420,7 @@ export default function useUserRepositories(user) {
420420

421421
return {
422422
repositories,
423-
getUserRepositories
423+
getUserRepositories,
424424
}
425425
}
426426
```
@@ -435,14 +435,14 @@ import { ref, computed } from 'vue'
435435
export default function useRepositoryNameSearch(repositories) {
436436
const searchQuery = ref('')
437437
const repositoriesMatchingSearchQuery = computed(() => {
438-
return repositories.value.filter(repository => {
438+
return repositories.value.filter((repository) => {
439439
return repository.name.includes(searchQuery.value)
440440
})
441441
})
442442

443443
return {
444444
searchQuery,
445-
repositoriesMatchingSearchQuery
445+
repositoriesMatchingSearchQuery,
446446
}
447447
}
448448
```
@@ -509,24 +509,19 @@ export default {
509509
props: {
510510
user: {
511511
type: String,
512-
required: true
513-
}
512+
required: true,
513+
},
514514
},
515515
setup(props) {
516516
const { user } = toRefs(props)
517517

518518
const { repositories, getUserRepositories } = useUserRepositories(user)
519519

520-
const {
521-
searchQuery,
522-
repositoriesMatchingSearchQuery
523-
} = useRepositoryNameSearch(repositories)
520+
const { searchQuery, repositoriesMatchingSearchQuery } =
521+
useRepositoryNameSearch(repositories)
524522

525-
const {
526-
filters,
527-
updateFilters,
528-
filteredRepositories
529-
} = useRepositoryFilters(repositoriesMatchingSearchQuery)
523+
const { filters, updateFilters, filteredRepositories } =
524+
useRepositoryFilters(repositoriesMatchingSearchQuery)
530525

531526
return {
532527
// Since we don’t really care about the unfiltered repositories
@@ -535,9 +530,9 @@ export default {
535530
getUserRepositories,
536531
searchQuery,
537532
filters,
538-
updateFilters
533+
updateFilters,
539534
}
540-
}
535+
},
541536
}
542537
```
543538

0 commit comments

Comments
 (0)