screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> </head> <body> <div id="app"> <div class="table-container"> <h3>Delete Table Row Dynamically in Vue Js </h3> <table> <thead> <tr> <th>ID</th> <th>Name</th> <th>Action</th> </tr> </thead> <tbody> <tr v-for="item in tableData" :key="item.id"> <td>{{ item.id }}</td> <td>{{ item.name }}</td> <td> <button class="cancel-button" @click="removeRow(item.id)">Remove</button> </td> </tr> </tbody> </table> </div> </div> <script type="module"> const app = Vue.createApp({ // Define the data properties and methods for the app data() { return { tableData: [ { id: 1, name: 'John' }, { id: 2, name: 'Jane' }, { id: 3, name: 'Bob' }, { id: 4, name: 'Andrew' }, { id: 5, name: 'James' }, { id: 6, name: 'Sherlock' }, ], }; }, methods: { removeRow(id) { const index = this.tableData.findIndex(item => item.id === id); if (index !== -1) { this.tableData.splice(index, 1); } }, }, }); app.mount("#app"); </script> <style scoped> /* CSS code */ .table-container { max-width: 600px; margin: 0 auto; } table { width: 100%; border-collapse: collapse; margin-bottom: 1em; } thead th { background-color: #f5f5f5; text-align: left; padding: 0.5em 1em; border-bottom: 1px solid #ddd; } tbody tr:nth-child(even) { background-color: #f9f9f9; } td { padding: 0.5em 1em; border-bottom: 1px solid #ddd; } td:first-child { font-weight: bold; } .cancel-button { background-color: #f44336; color: #fff; border: none; padding: 0.5em 1em; border-radius: 0.25em; font-size: 1em; cursor: pointer; transition: background-color 0.3s; } .cancel-button:hover { background-color: #e53935; } .cancel-button:focus { outline: none; box-shadow: 0 0 0 2px #ffcdd2; } </style> </body> </html>