Vue array operation, how to assign one array to another array?

1. The data area definition variables are as follows:

        all:[],
        current:[],       

2. The server returns 10 pieces of json data and assigns values to the all array. There is no problem here: this.all=response.data;
wants to assign the first five pieces of data of the all array to the current array. Try to use the for loop this.current [I] = this.all [I]. No, how should the value be assigned?

Mar.02,2021

this.current = this.all.slice(0,5)

it's not impossible to assign values in parentheses in Vue, but after assignment, updated, is not triggered, that is, the view is not updated.

you can change the array with methods such as push, pop, or point the pointer directly to a new array, such as the new array returned by slice,filter,map, etc., which will also trigger the view update.

can also change the value of the array by Vue.$set ().

Menu