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
Table of contents 1. Simple to use 2. Use DISTINC...
Linux file permissions First, let's check the...
Scenario 1: Html: <div class="outer"...
Table of contents 1. Preparation: 2. Source code ...
1. Preparation 1.1 harbor download harbor downloa...
Note: This demo is tested in the mini program env...
The so-called sliding door technology means that ...
The detailed process of using MySQL database with...
This article shares the MySQL Workbench installat...
I believe that students who have learned about th...
nohup command: If you are running a process and y...
Three knowledge points: 1. CSS descendant selecto...
ModSecurity is a powerful packet filtering tool t...
Effect html <body> <div class="cont...
The full name of SSH is Secure SHell. By using SS...