1
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?

More than 3 years have passed since last update.

Vueの監視プロパティwatchで配列やオブジェクトの変更を監視しても変更時取得される古い値と新しい値が同じな件

Last updated at Posted at 2020-04-21

リンク先の赤いびっくりマーク参照。
まーそういうことよね(・・`
https://jp.vuejs.org/v2/api/index.html#vm-watch

オブジェクトまたは配列を変更する(というよりむしろ置換する)とき、それらは同じオブジェクト/配列を参照するため、古い値は新しい値と同じになることに注意してください。Vue は変更前の値のコピーしません。

なのでdeep watchとかで配列やオブジェクトを監視する際旧値が必要な場合は
dataに旧値を手動保存しときましょーね

1
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
1
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?