Tips:
The array modification method is as follows: 1. arr.push() adds elements from the back
2. arr.pop() deletes the element from the back, only one
3. arr.shift() deletes elements from the front, only one can be deleted
4. arr.unshift() adds elements from the front and returns the length of the array after adding them
5. arr.splice(i,n) deletes N (number of deletions) starting from i (index value) let arr = [1,2,3,4,5] console.log(arr.splice(2,2)) //[3,4] console.log(arr) // [1,2,5] 6. arr.sort() sorts the array and returns the sorted array let arr = [2,10,6,1,4,22,3] console.log(arr.sort()) // [1, 10, 2, 22, 3, 4, 6] let arr1 = arr.sort((a, b) => a - b) console.log(arr1) // [1, 2, 3, 4, 6, 10, 22] let arr2 = arr.sort((a, b) => b a) console.log(arr2) // [22, 10, 6, 4, 3, 2, 1] 7. arr.reverse() reverses the array let arr = [1,2,3,4,5] console.log(arr.reverse()) // [5,4,3,2,1] console.log(arr) // [5,4,3,2,1] Array non-mutating methods are as follows: 1. arr.concat() connects two arrays let arr = [1,2,3,4,5] console.log(arr.concat([1,2])) // [1,2,3,4,5,1,2] console.log(arr) // [1,2,3,4,5] 2. arr.slice(start,end) cuts off the index from start to end, excluding the start index. let arr = [1,2,3,4,5] console.log(arr.slice(1,3)) // [2,3] Override Method <li v-for="(val, index) in arr" :key="index"> {{ val }} </li> <button @click="sliceBtn">Slice the first 3</button> sliceBtn(){ // 2. Array slice method will not cause v-for to update // slice will not change the original array // this.arr.slice(0, 3) // Solve v-for update - overwrite the original array let newArr = this.arr.slice(0, 3) this.arr = newArr }, this.$set() Method <li v-for="(val, index) in arr" :key="index"> {{ val }} </li> <button @click="sliceBtn">Update the value of index 0</button> sliceBtn(){ // When updating a value, v-for cannot detect it // this.arr[0] = 1000 // Solution - this.$set() // Parameter 1: Update target structure // Parameter 2: Update position // Parameter 3: Update value let newArr = this.arr.slice(0, 3) this.arr = newArr }, This is the end of this article about v-for update detection in Vue. For more relevant vue v-for update detection content, please search 123WORDPRESS.COM’s previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MySQL cursor functions and usage
>>: The solution to the problem that the web table or div layer is stretched in the web page
I recently deployed MySQL 5.6 and found that by d...
systemd: The service systemctl script of CentOS 7...
Generally, learning Java and deploying projects a...
webkit scrollbar style reset 1. The scrollbar con...
Absolute length px px is the pixel value, which i...
With the emergence of docker, many services have ...
What is a big deal? Transactions that run for a l...
The main contents of this article are as follows:...
Table of contents Introduction to NIS Network env...
Table of contents 1. Use help information 2. Crea...
GTID-based replication Introduction GTID-based re...
1. AIDE AIDE (Advanced Intrusion Detection Enviro...
1. Linux installation (root user operation) 1. In...
Preface: In Vue, props can be used to connect ori...
Table of contents 1. Software Package 2. Install ...