Skip to content

Commit d453f4b

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 84b478f + d4eaf6e commit d453f4b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1020
-784
lines changed

src/.vuepress/components/community/team/members.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ const members = [
252252
languages: ['uk', 'ru', 'en'],
253253
reposOfficial: ['vuejs.org', 'vue-cli'],
254254
work: {
255-
role: 'Senior Frontend Engineer',
255+
role: 'Staff Frontend Engineer',
256256
org: 'GitLab',
257257
orgUrl: 'https://gitlab.com/'
258258
},

src/.vuepress/config.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const sidebar = {
1515
'/guide/introduction',
1616
'/guide/instance',
1717
'/guide/template-syntax',
18+
'/guide/data-methods',
1819
'/guide/computed',
1920
'/guide/class-and-style',
2021
'/guide/conditional',
@@ -156,6 +157,7 @@ const sidebar = {
156157
'/api/global-api',
157158
{
158159
title: 'Options',
160+
path: '/api/options-api',
159161
collapsable: false,
160162
children: [
161163
'/api/options-data',
@@ -173,6 +175,7 @@ const sidebar = {
173175
'/api/built-in-components.md',
174176
{
175177
title: 'Reactivity API',
178+
path: '/api/reactivity-api',
176179
collapsable: false,
177180
children: [
178181
'/api/basic-reactivity',
@@ -251,10 +254,10 @@ module.exports = {
251254
],
252255
['meta', { name: 'msapplication-TileColor', content: '#000000' }],
253256
[
254-
('script',
257+
'script',
255258
{
256259
src: 'https://player.vimeo.com/api/player.js'
257-
})
260+
}
258261
],
259262
[
260263
'script',
@@ -295,7 +298,7 @@ module.exports = {
295298
},
296299
{
297300
text: 'API Reference',
298-
link: '/api/application-config'
301+
link: '/api/'
299302
},
300303
{
301304
text: 'Ecosystem',

src/.vuepress/public/images/css-vs-js-ease.svg

Lines changed: 1 addition & 1 deletion
Loading
-3.78 KB
Loading

src/.vuepress/theme/components/Newsletter.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
position: absolute;
7272
padding: 4px 20px;
7373
margin: 0;
74-
height: calc(100% - 8px);
74+
min-height: calc(100% - 8px);
7575
right: 4px;
7676
top: 4px;
7777
font-size: 1.05em;

src/api/composition-api.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,58 @@ const foo = inject<string>('foo') // string | undefined
158158
- **See also**:
159159
- [Provide / Inject](../guide/component-provide-inject.html)
160160
- [Composition API Provide / Inject](../guide/composition-api-provide-inject.html)
161+
162+
## `getCurrentInstance`
163+
164+
`getCurrentInstance` enables access to an internal component instance useful for advanced usages or for library creators.
165+
166+
```ts
167+
import { getCurrentInstance } from 'vue'
168+
169+
const MyComponent = {
170+
setup() {
171+
const internalInstance = getCurrentInstance()
172+
173+
internalInstance.appContext.config.globalProperties // access to globalProperties
174+
}
175+
}
176+
```
177+
178+
`getCurrentInstance` **only** works during [setup](#setup) or [Lifecycle Hooks](#lifecycle-hooks)
179+
180+
> When using outside of [setup](#setup) or [Lifecycle Hooks](#lifecycle-hooks), please call `getCurrentInstance()` on `setup` and use the instance instead.
181+
182+
```ts
183+
const MyComponent = {
184+
setup() {
185+
const internalInstance = getCurrentInstance() // works
186+
187+
const id = useComponentId() // works
188+
189+
const handleClick = () => {
190+
getCurrentInstance() // doesn't work
191+
useComponentId() // doesn't work
192+
193+
internalInstance // works
194+
}
195+
196+
onMounted(() => {
197+
getCurrentInstance() // works
198+
})
199+
200+
return () =>
201+
h(
202+
'button',
203+
{
204+
onClick: handleClick
205+
},
206+
`uid: ${id}`
207+
)
208+
}
209+
}
210+
211+
// also works if called on a composable
212+
function useComponentId() {
213+
return getCurrentInstance().uid
214+
}
215+
```

src/api/directives.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
<!-- shorthand -->
198198
<button @click="doThis"></button>
199199

200-
<!-- shorthand dynamic event (2.6.0+) -->
200+
<!-- shorthand dynamic event -->
201201
<button @[event]="doThis"></button>
202202

203203
<!-- stop propagation -->

src/api/index.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# API
2+
3+
The Vue.js API contains the following categories:
4+
5+
- [Application Config](/api/application-config.html)
6+
- [Application API](/api/application-api.html)
7+
- [Global API](/api/global-api.html)
8+
- [Options API](/api/options-api.html)
9+
- [Instance Properties](/api/instance-properties.html)
10+
- [Instance Methods](/api/instance-methods.html)
11+
- [Directives](/api/directives.html)
12+
- [Special Attributes](/api/special-attributes.html)
13+
- [Built-in Components](/api/built-in-components.html)
14+
- [Reactivity API](/api/reactivity-api.html)
15+
- [Composition API](/api/composition-api.html)

src/api/instance-methods.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- `{Object} options (optional)`
1010
- `{boolean} deep`
1111
- `{boolean} immediate`
12+
- `{string} flush`
1213

1314
- **Returns:** `{Function} unwatch`
1415

@@ -158,7 +159,9 @@
158159
If you still want to call an unwatch function inside the callback, you should check its availability first:
159160

160161
```js
161-
const unwatch = vm.$watch(
162+
let unwatch = null
163+
164+
unwatch = vm.$watch(
162165
'value',
163166
function() {
164167
doSomething()
@@ -170,6 +173,24 @@
170173
)
171174
```
172175

176+
- **Option: flush**
177+
178+
The `flush` option allows for greater control over the timing of the callback. It can be set to `'pre'`, `'post'` or `'sync'`.
179+
180+
The default value is `'pre'`, which specifies that the callback should be invoked before rendering. This allows the callback to update other values before the template runs.
181+
182+
The value `'post'` can be used to defer the callback until after rendering. This should be used if the callback needs access to the updated DOM or child components via `$refs`.
183+
184+
If `flush` is set to `'sync'`, the callback will be called synchronously, as soon as the value changes.
185+
186+
For both `'pre'` and `'post'`, the callback is buffered using a queue. The callback will only be added to the queue once, even if the watched value changes multiple times. The interim values will be skipped and won't be passed to the callback.
187+
188+
Buffering the callback not only improves performance but also helps to ensure data consistency. The watchers won't be triggered until the code performing the data updates has finished.
189+
190+
`'sync'` watchers should be used sparingly, as they don't have these benefits.
191+
192+
For more information about `flush` see [Effect Flush Timing](../guide/reactivity-computed-watchers.html#effect-flush-timing).
193+
173194
- **See also:** [Watchers](../guide/computed.html#watchers)
174195

175196
## $emit

src/api/instance-properties.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
The root DOM element that the component instance is managing.
3030

31+
For components using [fragments](../guide/migration/fragments), `$el` will be the placeholder DOM node that Vue uses to keep track of the component's position in the DOM. It is recommended to use [template refs](../guide/component-template-refs.html) for direct access to DOM elements instead of relying on `$el`.
32+
3133
## $options
3234

3335
- **Type:** `Object`

0 commit comments

Comments
 (0)