In the vue project, how do you add an item to an array using the $set () method?

for example: obj = {name: "wh"}, add obj to arr = [1,2,3], and the implementation result is arr = [{name:" wh"}, 1,2,3]


just use the push method of the array directly.
of course, if you must use $set, just set the length of the array as the key


arr.ubshift (obj)


first of all, do you understand when the set is used? Secondly, the people who answered did not care why the landlord used $set. Just change the array directly, if the array you modified is not bidirectionally bound to the view layer, and your requirements need to be updated by the view layer, what's the use of using ubshift and changing the array directly?

Menu