screen_rotation
Copied to Clipboard
<html> <head> <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> </head> <body> <h3>Vue Js Single Select Chips from Dropdown</h3> <div id="app"> <div class="chip" v-if="selectedItem"> {{ selectedItem }} <span class="close" @click="remove">x</span> </div> <div class="dropdown"> <div class="selected-item" @click="toggleDropdown">{{ selectedItem }}</div> <ul class="dropdown-list" v-show="showDropdown"> <li class="dropdown-item" v-for="item in items" @click="selectItem(item)">{{ item }}</li> </ul> </div> </div> <script type="module"> const app = new Vue({ el: "#app", data() { return { items: ['HTML', 'CSS', 'React','Vue','Angular','Node','PHP'], selectedItem: 'CSS', showDropdown: false } }, methods: { toggleDropdown() { this.showDropdown = !this.showDropdown; }, selectItem(item) { this.selectedItem = item; this.showDropdown = false; }, remove() { this.selectedItem = ''; } } }); </script> <style> .dropdown { position: relative; } .selected-item { cursor: pointer; padding: 8px 12px; border: 1px solid #ccc; border-radius: 4px; } .dropdown-list { position: absolute; top: 100%; left: 0; right: 0; background-color: #fff; border: 1px solid #ccc; border-top: none; z-index: 1; margin:0 } .dropdown-item { cursor: pointer; padding: 8px 12px; border-bottom: 1px solid #ccc; } .chip { background-color: #ccc; color: #fff; padding: 4px 8px; border-radius: 4px; margin-left: 8px; display: inline-flex; align-items: center; margin-bottom:1rem } .close { cursor: pointer; margin-left: 8px; } </style> </body> </html>