How does Vue.set delete an item in an array

Vue.set(cardList,1,"");
Vue.set(cardList,1,false);
Vue.set(cardList,1,null);

according to Vue.set (data,key,value), I want to delete an item in the array cardList. The above three values cannot be deleted and will be replaced directly. I would like to delete this item directly.

clipboard.png

Jul.14,2021

1. Now delete an item from the array, and then the new array replaces the old array.
2. Another is the variation method provided in the documentation ide/list.html-sharp%E5%8F%98%E5%BC%82%E6%96%B9%E6%B3%95" rel=" nofollow noreferrer "> https://cn.vuejs.org/v2/guide.


splice (index,len, [item]) it can also be used to replace / delete / add one or more values in the array (this method changes the original array)
index: array start subscript
length of len: replacement / deletion
item: replacement value, item is empty for delete operation

/ / Delete a value with a starting subscript of 1 and a length of 1 (len setting 1, if 0, the array remains the same)
var arr = ['axiaozhongjiezhuo'];
arr.splice (1meme1);
console.log (arr); / / ['axiaojiaoyuzhongd'];


first of all, if you want to delete an item in the array, you can directly use
arr.splice (index,1) splice has been processed by vue and can be bound in both directions. You can see the document.
ide/list.html-sharp%E6%95%B0%E7%BB%84%E6%9B%B4%E6%96%B0%E6%A3%80%E6%B5%8B" rel=" nofollow noreferrer "vue

if you want to verify the use of the set instance method in vue, it is not wrong. The set method helps us change some inputs in the arr array prototype, such as length, value, etc.
you are using
`Vue.set (cardList,key,'');
Vue.set (cardList,key,false);
Vue.set (cardList,key,null); `
can only achieve a replacement.

for example, if you want to replace the key value name in the first object of an array object, you can use
Vue.set (cardlist, key,value)

.

if you want to delete a key value under an object in an array object, you can only delete or replace the object with an empty one and then load it with the value you need


try Vue.delete ()

Menu