screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3.2.21/dist/vue.global.js"></script> </head> <body> <div id="app"> <h3>Vue Table with Search </h3> <input type="text" v-model="search" placeholder="Search"> <div class='error-message'v-if="filteredData.length === 0"> No data found. </div> <table v-else> <thead> <tr> <th v-for="column in columns" :key="column">{{ column }}</th> </tr> </thead> <tbody> <tr v-for="row in filteredData" :key="row.id"> <td v-for="column in columns" :key="column">{{ row[column] }}</td> </tr> </tbody> </table> </div> <script type="module"> const app = Vue.createApp({ data() { return { columns: ['name', 'age', 'gender'], rows: [ { id: 1, name: 'John Doe', age: 30, gender: 'Male' }, { id: 2, name: 'Jane Doe', age: 25, gender: 'Female' }, { id: 3, name: 'Bob Smith', age: 40, gender: 'Male' }, ], search: '' } }, computed: { filteredData() { return this.rows.filter(row => { return Object.values(row).some(value => { return String(value).toLowerCase().includes(this.search.toLowerCase()); }); }); } } }); app.mount('#app'); </script> <style scoped> #app { font-family: Arial, sans-serif; margin: 0 auto; max-width: 800px; padding: 20px; } h3 { color: #333; font-size: 24px; margin-bottom: 20px; text-align: center; } input[type="text"] { border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; font-size: 16px; padding: 10px; width: 100%; } table { border-collapse: collapse; margin-top: 20px; width: 100%; } thead { background-color: #333; color: #fff; } thead th { font-size: 16px; font-weight: bold; padding: 10px; text-align: left; } tbody tr { border-bottom: 1px solid #ccc; } tbody tr:hover { background-color: #f5f5f5; } tbody td { font-size: 14px; padding: 10px; } .error-message { color: red; font-size: 18px; margin-top: 10px; text-align: center; } </style> </body> </html>