Skip to content

Commit b7daaed

Browse files
authored
Merge branch 'vuejs-jp:lang-ja' into update-5th-week-of-june
2 parents 51ba5fe + a52eee9 commit b7daaed

13 files changed

+302
-186
lines changed

src/api/basic-reactivity.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,44 @@ The reactive conversion is "deep"—it affects all nested properties. In the [ES
1818
function reactive<T extends object>(target: T): UnwrapNestedRefs<T>
1919
```
2020

21+
::: tip Note
22+
`reactive` will unwrap all the deep [refs](./refs-api.html#ref), while maintaining the ref reactivity
23+
24+
```ts
25+
const count = ref(1)
26+
const obj = reactive({ count })
27+
28+
// ref will be unwrapped
29+
console.log(obj.count === count.value) // true
30+
31+
// it will update `obj.count`
32+
count.value++
33+
console.log(count.value) // 2
34+
console.log(obj.count) // 2
35+
36+
// it will also update `count` ref
37+
obj.count++
38+
console.log(obj.count) // 3
39+
console.log(count.value) // 3
40+
```
41+
42+
:::
43+
44+
::: warning Important
45+
When assigning a [ref](./refs-api.html#ref) to a `reactive` property, that ref will be automatically unwrapped.
46+
47+
```ts
48+
const count = ref(1)
49+
const obj = reactive({})
50+
51+
obj.count = count
52+
53+
console.log(obj.count) // 1
54+
console.log(obj.count === count.value) // true
55+
```
56+
57+
:::
58+
2159
## `readonly`
2260

2361
Takes an object (reactive or plain) or a [ref](./refs-api.html#ref) and returns a readonly proxy to the original. A readonly proxy is deep: any nested property accessed will be readonly as well.
@@ -39,6 +77,19 @@ original.count++
3977
copy.count++ // warning!
4078
```
4179

80+
As with [`reactive`](#reactive), if any property uses a `ref` it will be automatically unwrapped when it is accessed via the proxy:
81+
82+
```js
83+
const raw = {
84+
count: ref(123)
85+
}
86+
87+
const copy = readonly(raw)
88+
89+
console.log(raw.count.value) // 123
90+
console.log(copy.count) // 123
91+
```
92+
4293
## `isProxy`
4394

4495
Checks if an object is a proxy created by [`reactive`](#reactive) or [`readonly`](#readonly).
@@ -153,6 +204,8 @@ isReactive(state.nested) // false
153204
state.nested.bar++ // non-reactive
154205
```
155206

207+
Unlike [`reactive`](#reactive), any property that uses a [`ref`](/api/refs-api.html#ref) will **not** be automatically unwrapped by the proxy.
208+
156209
## `shallowReadonly`
157210

158211
Creates a proxy that makes its own properties readonly, but does not perform deep readonly conversion of nested objects (exposes raw values).
@@ -171,3 +224,5 @@ state.foo++
171224
isReadonly(state.nested) // false
172225
state.nested.bar++ // works
173226
```
227+
228+
Unlike [`readonly`](#readonly), any property that uses a [`ref`](/api/refs-api.html#ref) will **not** be automatically unwrapped by the proxy.

src/api/computed-watch-api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function watchEffect(
6565
): StopHandle
6666
6767
interface WatchEffectOptions {
68-
flush?: 'pre' | 'post' | 'sync'
68+
flush?: 'pre' | 'post' | 'sync' // default: 'pre'
6969
onTrack?: (event: DebuggerEvent) => void
7070
onTrigger?: (event: DebuggerEvent) => void
7171
}
@@ -132,7 +132,7 @@ watch([fooRef, barRef], ([foo, bar], [prevFoo, prevBar]) => {
132132
**Typing:**
133133

134134
```ts
135-
// wacthing single source
135+
// watching single source
136136
function watch<T>(
137137
source: WatcherSource<T>,
138138
callback: (

src/api/instance-methods.md

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@
99
- `{Object} options (optional)`
1010
- `{boolean} deep`
1111
- `{boolean} immediate`
12+
- `{string} flush`
1213

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

1516
- **Usage:**
1617

17-
Watch a reactive property or a computed function on the component instance for changes. The callback gets called with the new value and the old value for the given property. We can only pass top-level `data`, `prop`, or `computed` property name as a string. For more complex expressions or nested properties, use a function instead.
18+
Watch a reactive property or a computed function on the component instance for changes. The callback gets called with the new value and the old value for the given property. We can only pass top-level `data`, `props`, or `computed` property name as a string. For more complex expressions or nested properties, use a function instead.
1819

1920
- **Example:**
2021

2122
```js
22-
const app = Vue.createApp({
23+
const app = createApp({
2324
data() {
2425
return {
2526
a: 1,
@@ -58,10 +59,10 @@
5859
})
5960
```
6061

61-
When watched value is an Object or Array, any changes to its properties or elements won't trigger the watcher because they reference the same Object/Array:
62+
When watched value is an object or array, any changes to its properties or elements won't trigger the watcher because they reference the same object/array:
6263

6364
```js
64-
const app = Vue.createApp({
65+
const app = createApp({
6566
data() {
6667
return {
6768
article: {
@@ -80,16 +81,16 @@
8081
})
8182
},
8283
methods: {
83-
// These methods won't trigger a watcher because we changed only a property of Object/Array,
84-
// not the Object/Array itself
84+
// These methods won't trigger a watcher because we changed only a property of object/array,
85+
// not the object/array itself
8586
changeArticleText() {
8687
this.article.text = 'Vue 3 is awesome'
8788
},
8889
addComment() {
8990
this.comments.push('New comment')
9091
},
9192

92-
// These methods will trigger a watcher because we replaced Object/Array completely
93+
// These methods will trigger a watcher because we replaced object/array completely
9394
changeWholeArticle() {
9495
this.article = { text: 'Vue 3 is awesome' }
9596
},
@@ -103,7 +104,7 @@
103104
`$watch` returns an unwatch function that stops firing the callback:
104105

105106
```js
106-
const app = Vue.createApp({
107+
const app = createApp({
107108
data() {
108109
return {
109110
a: 1
@@ -120,7 +121,9 @@
120121

121122
- **Option: deep**
122123

123-
To also detect nested value changes inside Objects, you need to pass in `deep: true` in the options argument. Note that you don't need to do so to listen for Array mutations.
124+
To also detect nested value changes inside Objects, you need to pass in `deep: true` in the options argument. This option also can be used to watch array mutations.
125+
126+
> Note: when mutating (rather than replacing) an Object or an Array and watch with deep option, the old value will be the same as new value because they reference the same Object/Array. Vue doesn't keep a copy of the pre-mutate value.
124127
125128
```js
126129
vm.$watch('someObject', callback, {
@@ -158,7 +161,9 @@
158161
If you still want to call an unwatch function inside the callback, you should check its availability first:
159162

160163
```js
161-
const unwatch = vm.$watch(
164+
let unwatch = null
165+
166+
unwatch = vm.$watch(
162167
'value',
163168
function() {
164169
doSomething()
@@ -170,6 +175,24 @@
170175
)
171176
```
172177

178+
- **Option: flush**
179+
180+
The `flush` option allows for greater control over the timing of the callback. It can be set to `'pre'`, `'post'` or `'sync'`.
181+
182+
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.
183+
184+
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`.
185+
186+
If `flush` is set to `'sync'`, the callback will be called synchronously, as soon as the value changes.
187+
188+
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.
189+
190+
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.
191+
192+
`'sync'` watchers should be used sparingly, as they don't have these benefits.
193+
194+
For more information about `flush` see [Effect Flush Timing](../guide/reactivity-computed-watchers.html#effect-flush-timing).
195+
173196
- **See also:** [Watchers](../guide/computed.html#watchers)
174197

175198
## $emit
@@ -272,7 +295,7 @@
272295
- **Example:**
273296

274297
```js
275-
Vue.createApp({
298+
createApp({
276299
// ...
277300
methods: {
278301
// ...

src/api/instance-properties.md

Lines changed: 10 additions & 6 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`
@@ -39,7 +41,7 @@
3941
The instantiation options used for the current component instance. This is useful when you want to include custom properties in the options:
4042

4143
```js
42-
const app = Vue.createApp({
44+
const app = createApp({
4345
customOption: 'foo',
4446
created() {
4547
console.log(this.$options.customOption) // => 'foo'
@@ -100,14 +102,15 @@
100102
```
101103

102104
```js
103-
const app = Vue.createApp({})
105+
const { createApp, h } = Vue
106+
const app = createApp({})
104107

105108
app.component('blog-post', {
106109
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())
110+
return h('div', [
111+
h('header', this.$slots.header()),
112+
h('main', this.$slots.default()),
113+
h('footer', this.$slots.footer())
111114
])
112115
}
113116
})
@@ -144,3 +147,4 @@ Contains parent-scope attribute bindings and events that are not recognized (and
144147

145148
- **See also:**
146149
- [Non-Prop Attributes](../guide/component-attrs.html)
150+
- [Options / Misc - inheritAttrs](./options-misc.html#inheritattrs)

src/api/options-api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# オプション
1+
# オプション API
22

3-
オプションには、次のようなセクションがあります:
3+
オプション API には、次のようなセクションがあります:
44

55
- [Data](/api/options-data.html)
66
- [DOM](/api/options-dom.html)
77
- [Lifecycle Hooks](/api/options-lifecycle-hooks.html)
88
- [Assets](/api/options-assets.html)
99
- [Composition](/api/options-composition.html)
10-
- [Misc](/api/options-misc.html)
10+
- [Miscellaneous](/api/options-misc.html)

src/api/options-assets.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@
88

99
A hash of directives to be made available to the component instance.
1010

11+
- **Usage:**
12+
13+
```js
14+
const app = createApp({})
15+
16+
app.component('focused-input', {
17+
directives: {
18+
focus: {
19+
mounted(el) {
20+
el.focus()
21+
}
22+
}
23+
},
24+
template: `<input v-focus>`
25+
})
26+
```
27+
1128
- **See also:** [Custom Directives](../guide/custom-directive.html)
1229

1330
## components
@@ -18,4 +35,19 @@
1835

1936
A hash of components to be made available to the component instance.
2037

38+
- **Usage:**
39+
40+
```js
41+
const Foo = {
42+
template: `<div>Foo</div>`
43+
}
44+
45+
const app = createApp({
46+
components: {
47+
Foo
48+
},
49+
template: `<Foo />`
50+
})
51+
```
52+
2153
- **See also:** [Components](../guide/component-basics.html)

src/api/options-composition.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020
}
2121

22-
Vue.createApp({
22+
createApp({
2323
created() {
2424
console.log(2)
2525
},
@@ -299,7 +299,7 @@ The `setup` function is a new component option. It serves as the entry point for
299299
}
300300
```
301301

302-
`attrs` and `slots` are proxies to the corresponding values on the internal component instance. This ensures they always expose the latest values even after updates so that we can destructure them without worrying accessing a stale reference:
302+
`attrs` and `slots` are proxies to the corresponding values on the internal component instance. This ensures they always expose the latest values even after updates so that we can destructure them without worrying about accessing a stale reference:
303303

304304
```js
305305
const MyComponent = {

0 commit comments

Comments
 (0)