Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to detect the changes of objects and arrays in vue

Shulou Source: shulou.com Published: 2022-05-31 12:01:00 09月27日 Update

This article focuses on "how to detect changes in objects and arrays in vue". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn how to detect changes in objects and arrays in vue.

Detect changes in objects

1. Cannot detect the addition or deletion of object attributes

Var vm = new Vue ({data: {data111: {a = 1})

Data111.a = 2 / this can cause a change.

But data111.b = 2; and vm.b = 2 cannot detect change.

Need to use

Vue.set (object, key, value)

For example, $set (data111, b, 2)

Or:

$set (key,value)

For example, vm.$set ('baked, 2)

Detect array changes

Changes cannot be detected in the following two situations:

1. Set elements directly through the index, such as arr [0] = 12

2. Directly modify the length of the array, such as vm.arr.length

Vue.set (object, key, value)

Usage:

This.$set (this.arr,0,12)

At this point, I believe you have a deeper understanding of "how to detect changes in objects and arrays in vue". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Change detection object array content learning utility deeper element interest practicality actual attribute situation simple operation method more friends index website Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Apple Shulou Technology MySQL Shulou Information