Skip to content

Commit 31417bd

Browse files
committed
fix: code style in reactivity-computed-watchers.md
vuejs/docs@fd21397
1 parent 646c332 commit 31417bd

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/guide/reactivity-computed-watchers.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ watchEffect(async (onInvalidate) => {
9595

9696
Vue のリアクティブシステムは、無効になった変更をバッファリングし、非同期に処理することによって、おなじ "tick" の中での複数の状態の変化に対して、不要な重複の呼び出しを避けることができています。内部的には、コンポーネントの `update` 関数も、監視されている作用の 1 つです。ユーザーによる作用がキューに入っている場合、デフォルトではすべてのコンポーネントの更新の **前に** 呼び出されます:
9797

98-
```html
99-
98+
```vue
10099
<template>
101100
<div>{{ count }}</div>
102101
</template>
@@ -201,15 +200,15 @@ watch(count, (count, prevCount) => {
201200
ウォッチャは、配列を利用することで、複数のデータソースを同時に監視できます:
202201

203202
```js
204-
const firstName = ref('');
205-
const lastName = ref('');
203+
const firstName = ref('')
204+
const lastName = ref('')
206205

207206
watch([firstName, lastName], (newValues, prevValues) => {
208-
console.log(newValues, prevValues);
207+
console.log(newValues, prevValues)
209208
})
210209

211-
firstName.value = "John"; // logs: ["John",""] ["", ""]
212-
lastName.value = "Smith"; // logs: ["John", "Smith"] ["John", ""]
210+
firstName.value = 'John' // logs: ["John", ""] ["", ""]
211+
lastName.value = 'Smith' // logs: ["John", "Smith"] ["John", ""]
213212
```
214213

215214
### リアクティブなオブジェクトの監視
@@ -222,8 +221,9 @@ const numbers = reactive([1, 2, 3, 4])
222221
watch(
223222
() => [...numbers],
224223
(numbers, prevNumbers) => {
225-
console.log(numbers, prevNumbers);
226-
})
224+
console.log(numbers, prevNumbers)
225+
}
226+
)
227227

228228
numbers.push(5) // logs: [1,2,3,4,5] [1,2,3,4]
229229
```
@@ -234,59 +234,59 @@ numbers.push(5) // logs: [1,2,3,4,5] [1,2,3,4]
234234
const state = reactive({
235235
id: 1,
236236
attributes: {
237-
name: "",
238-
},
239-
});
237+
name: ''
238+
}
239+
})
240240

241241
watch(
242242
() => state,
243243
(state, prevState) => {
244244
console.log(
245-
"not deep ",
245+
'not deep',
246246
state.attributes.name,
247247
prevState.attributes.name
248-
);
248+
)
249249
}
250-
);
250+
)
251251

252252
watch(
253253
() => state,
254254
(state, prevState) => {
255255
console.log(
256-
"deep ",
256+
'deep',
257257
state.attributes.name,
258258
prevState.attributes.name
259-
);
259+
)
260260
},
261261
{ deep: true }
262-
);
262+
)
263263

264-
state.attributes.name = "Alex"; // Logs: "deep " "Alex" "Alex"
264+
state.attributes.name = 'Alex' // Logs: "deep" "Alex" "Alex"
265265
```
266266

267267
しかし、リアクティブなオブジェクトや配列を監視すると、そのオブジェクトの状態の現在値と前回値の両方について参照が常に返されます。深くネストされたオブジェクトや配列を完全に監視するためには、値のディープコピーが必要な場合があります。これは [lodash.cloneDeep](https://lodash.com/docs/4.17.15#cloneDeep) のようなユーティリティで実現できます。
268268

269269
```js
270-
import _ from 'lodash';
270+
import _ from 'lodash'
271271

272272
const state = reactive({
273273
id: 1,
274274
attributes: {
275-
name: "",
276-
},
277-
});
275+
name: ''
276+
}
277+
})
278278

279279
watch(
280280
() => _.cloneDeep(state),
281281
(state, prevState) => {
282282
console.log(
283283
state.attributes.name,
284284
prevState.attributes.name
285-
);
285+
)
286286
}
287-
);
287+
)
288288

289-
state.attributes.name = "Alex"; // Logs: "Alex" ""
289+
state.attributes.name = 'Alex'; // Logs: "Alex" ""
290290
```
291291

292292
### `watchEffect` との振る舞いの共有

0 commit comments

Comments
 (0)