screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3.2.26/dist/vue.global.js"></script> </head> <body> <h3>Vue Remove Item from Array by Index</h3> <div id="app"> <ul> <li v-for="(item, index) in items" :key="index"> <span>{{ item.name }}</span> <span>{{ item.description }}</span> <button @click="deleteItem(index)">Delete</button> </li> </ul> </div> <script> const app = Vue.createApp({ data() { return { items: [ { name: 'Item 1', description: 'Description 1' }, { name: 'Item 2', description: 'Description 2' }, { name: 'Item 3', description: 'Description 3' } ], }; }, methods: { deleteItem(index) { this.items.splice(index, 1); }, }, }); app.mount('#app'); </script> <style scoped> ul { list-style: none; padding: 0; } li { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #ccc; padding: 10px; } li:last-child { border-bottom: none; } button { background-color: #f44336; border: none; color: white; padding: 10px 15px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin-left: 10px; cursor: pointer; } button:hover { background-color: #e53935; } input[type=text] { width: 100%; padding: 12px 20px; margin: 8px 0; box-sizing: border-box; border: 2px solid #ccc; border-radius: 4px; font-size: 16px; } input[type=submit] { background-color: #4CAF50; color: white; padding: 12px 20px; border: none; border-radius: 4px; cursor: pointer; } input[type=submit]:hover { background-color: #45a049; } </style> </body> </html>