業界トップクラスの求人数を誇る転職エージェントPR

リクルートグループのコネクションを活かした非公開求人も充実、他にはない好条件の求人と出会える

0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Vue3.5のwatchやライフサイクルフックの実行タイミング

Last updated at Posted at 2025-02-25

はじめに

Vueのライフサイクルフックが呼ばれる順番はここで案内されている。
https://ja.vuejs.org/guide/essentials/lifecycle.html

watchは即時ウォッチャーと
https://ja.vuejs.org/guide/essentials/watchers.html#eager-watchers

遅延ウォッチャーなどがある。
https://ja.vuejs.org/guide/essentials/watchers.html#post-watchers

これらの実行タイミングは明記されていない。
Vue Playgroundで試してみた

結論

まとめるとこう。

コンポーネントがインスタンス化される(v-ifがtrueになるなど)

watch { immediate: true }(flushの値は関係ない)

onBeforeMount

onMounted

refの値を変更する

watch: { flush: "sync" }

watch: { flush: "pre" }(デフォルトの挙動)

onBeforeUpdate

watch: { flush: "post" }

onUpdated

おわりに

onMountedした直後に必ず1回watchコールバックを実行する方法を探していたけど、なさそうだった。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?