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

前端 未结 8 1115
小蘑菇
小蘑菇 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 03:00

    You can delete item through id

    
    

    Inside your JS code

    deleteEvent(id){
      this.events = this.events.filter((e)=>e.id !== id )
    }
    

    Vue wraps an observed array’s mutation methods so they will also trigger view updates. Click here for more details.

    You might think this will cause Vue to throw away the existing DOM and re-render the entire list - luckily, that is not the case.

提交回复
热议问题