screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.0/html2canvas.min.js"></script> </head> <body> <div id="app"> <h3>How To Create a Filter/Search array Vue Js</h3> <div class="search-box"> <label for="search">Search:</label> <input type="text" id="search" v-model="searchText"> </div> <ul class="item-list"> <li v-for="item in filteredItems" :key="item.name"> {{ item.name }} - {{ item.category }} </li> <li v-if="filteredItems.length === 0"> No items found. </li> </ul> </div> <script type="module"> const app = Vue.createApp({ data() { return { items: [ { name: "Apple", category: "Fruit" }, { name: "Banana", category: "Fruit" }, { name: "Carrot", category: "Vegetable" }, { name: "Broccoli", category: "Vegetable" } ], searchText: "" }; }, computed: { filteredItems() { return this.items.filter(item => { return ( item.name.toLowerCase().includes(this.searchText.toLowerCase()) || item.category.toLowerCase().includes(this.searchText.toLowerCase()) ); }); } } }) app.mount('#app') </script> <style scoped> #app { max-width: 500px; margin: 0 auto; } .search-box { display: flex; align-items: center; margin-bottom: 1rem; } .search-box label { margin-right: 0.5rem; } .item-list { list-style: none; margin: 0; padding: 0; } .item-list li { margin-bottom: 0.5rem; padding: 0.5rem; border: 1px solid #ccc; border-radius: 3px; } </style> </body> </html>