Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to detect the changes of objects and arrays in vue

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report