screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> </head> <body> <h3>Vue Js Remove Item from Array by Id </h3> <div id="app"> <ul> <li v-for="item in items" :key="item.id"> {{ item.name }} <button @click="removeItem(item.id)">Remove</button> </li> </ul> </div> <script type="module"> const app = Vue.createApp({ data() { return { items: [ { id: 1, name: 'VUE' }, { id: 2, name: 'React' }, { id: 3, name: 'Angular' }, { id: 4, name: 'PHP' } ] }; }, methods: { removeItem(id) { const index = this.items.findIndex(item => item.id === id) if (index !== -1) { this.items.splice(index, 1) } } } }); app.mount('#app'); </script> </body> </html>