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
But a key difference to lifecycle hooks is that `watch()`and`watchEffect()`effects are run *before* the DOM is mounted or updated so the template ref hasn't been updated when the watcher runs the effect:
@@ -105,8 +105,8 @@ But a key difference to lifecycle hooks is that `watch()` and `watchEffect()` ef
105
105
const root = ref(null)
106
106
107
107
watchEffect(() => {
108
-
// This effect runs before the DOM is updated, and consequently,
109
-
// the template ref does not hold a reference to the element yet.
108
+
// この作用は DOM が更新される前に実行され、
109
+
// 結果的にテンプレート参照は、まだ要素への参照を保持していません。
110
110
console.log(root.value) // => null
111
111
})
112
112
@@ -118,7 +118,7 @@ But a key difference to lifecycle hooks is that `watch()` and `watchEffect()` ef
118
118
</script>
119
119
```
120
120
121
-
Therefore, watchers that use template refs should be defined with the `flush: 'post'`option. This will run the effect *after* the DOM has been updated and ensure that the template ref stays in sync with the DOM and references the correct element.
121
+
そのため、テンプレート参照を使うウォッチャは、 `flush: 'post'`オプションをつけて定義する必要があります。これにより、DOM が更新された *あとに* 作用が実行され、テンプレート参照が DOM と同期して、正しい要素を参照するようになります。
122
122
123
123
```vue
124
124
<template>
@@ -147,4 +147,4 @@ Therefore, watchers that use template refs should be defined with the `flush: 'p
147
147
</script>
148
148
```
149
149
150
-
*See also: [Computed and Watchers](./reactivity-computed-watchers.html#effect-flush-timing)
0 commit comments