How to remove an item from an array in Vue.js

前端 未结 8 1124
小蘑菇
小蘑菇 2020-11-29 02:24

I am new to vue.js (2) and I am currently working on a simple event app. I\'ve managed to add events but now I would like to delete events based on clicking on a button.

8条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 02:43

    Splice is the best to remove element from specific index. The given example is tested on console.

    card = [1, 2, 3, 4];
    card.splice(1,1);  // [2]
    card   // (3) [1, 3, 4]
    splice(startingIndex, totalNumberOfElements)
    

    startingIndex start from 0.

提交回复
热议问题