1. Vue listener arrayVue can actually monitor array changes, such as data () { return { watchArr: [], }; }, watchArr (newVal) { console.log('Listening: ' + newVal); }, created () { setTimeout(() => { this.watchArr = [1, 2, 3]; }, 1000); }, For example, use splice(0,2,3) to delete two elements from array index 0 and insert an element 3 at index 0. data () { return { watchArr: [1, 2, 3], }; }, watchArr (newVal) { console.log('Listening: ' + newVal); }, created () { setTimeout(() => { this.watchArr.splice(0, 2, 3); }, 1000); }, The push array can also be monitored. 2. Situations where vue cannot monitor array changesHowever, arrays cannot be monitored in the following two situations
Example of a situation where array changes cannot be monitored 1. Use indexes to modify array values directly data () { return { watchArr: [{ name: 'krry', }], }; }, watchArr (newVal) { console.log('Listening: ' + newVal); }, created () { setTimeout(() => { this.watchArr[0].name = 'xiaoyue'; }, 1000); }, 2. Modify the length of the array
data () { return { watchArr: [{ name: 'krry', }], }; }, watchArr (newVal) { console.log('Listening: ' + newVal); }, created () { setTimeout(() => { this.watchArr.length = 5; }, 1000); }, This is the end of this article about Vue not being able to watch array changes. For more related content about Vue not being able to watch array changes, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of Docker usage under CentOS8
>>: Reasons and optimization solutions for slow MySQL limit paging with large offsets
This article shares with you the installation tut...
background I am learning nodejs recently, and I r...
Table of contents plan Install Dependencies Intro...
Why did I use this? It all started with the makin...
Preface When developing a gateway project, the si...
This article shares a common example of viewing p...
Enable remote access to MySQL By default, MySQL u...
Background-image is probably one of those CSS pro...
When the database concurrently adds, deletes, and...
Clickhouse Introduction ClickHouse is a column-or...
How to use css variables in JS Use the :export ke...
The key is that the local server does not have wr...
Moore's Law no longer applies Starting with F...
Because a certain function of my project requires...
Treemaps are mainly used to visualize tree-like d...