From e89d2f02233370260faa26eae68819f94e906e14 Mon Sep 17 00:00:00 2001 From: yiming <m13691596795@163.com> Date: 星期三, 07 八月 2024 16:06:48 +0800 Subject: [PATCH] Merge branch 'master' of http://182.92.203.7:2001/r/testbookLayout --- src/components/dropdown/index.vue | 73 ++++++++++++++++++++---------------- 1 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/components/dropdown/index.vue b/src/components/dropdown/index.vue index 4bc6df6..7e50256 100644 --- a/src/components/dropdown/index.vue +++ b/src/components/dropdown/index.vue @@ -1,33 +1,18 @@ <template> <div class="dropdown"> - <div class="selected-option" > + <div class="selected-option"> <div class="selected-values"> - <span - v-for="(option, index) in selectedOptions" - :key="index" - class="selected-value" - > + <span v-for="(option, index) in selectedOptions" :key="index" class="selected-value"> <span class="selected-value-txt">{{ option }}</span> <span class="delete" @click="removeOption(option)"> × </span> </span> </div> - <input - type="text" - v-model="searchText" - placeholder="璇烽�夋嫨閫夐」" - @input="filterOptions" - v-if="isShowSearch" - /> + <input type="text" v-model="searchText" placeholder="璇烽�夋嫨閫夐」" @input="filterOptions" v-if="isShowSearch" /> <span class="arrow" @click="toggleDropdown"></span> </div> - <!-- <button class="confirm-button" @click="submitSelection">纭</button> --> <ul v-if="showDropdown" class="options-list"> - <li - v-for="option in filteredOptions" - :key="option" - @click="toggleOption(option)" - > + <li v-for="option in filteredOptions" :key="option" @click="toggleOption(option)"> <input type="checkbox" :value="option" :checked="isSelected(option)" /> <label>{{ option }}</label> </li> @@ -37,13 +22,16 @@ <script> export default { - props:{ - options:{ - type:Array + props: { + options: { + type: Array }, - isShowSearch:{ - type:Boolean, - default:false + value: { + type: Array + }, + isShowSearch: { + type: Boolean, + default: false } }, data() { @@ -54,6 +42,7 @@ searchText: "", // 杩囨护閫夐」鐨勬悳绱㈡枃鏈� // ... showConfirmButton: false, + selected: this.value }; }, computed: { @@ -62,14 +51,22 @@ option.toLowerCase().includes(this.searchText.toLowerCase()) ); }, + }, - watch:{ - selectedOptions:{ + watch: { + value: { + deep: true, // 娣卞害鐩戣(閽堝澶嶆潅绫诲瀷) + immediate: true, // 鏄惁绔嬪埢鎵ц涓�娆andler handler(newValue) { - console.log('閫変腑椤瑰彉鍖�',newValue); - this.$emit('changeDropdownData',newValue) + this.selectedOptions = newValue + } - },deep:true + }, + selectedOptions: { + handler(newValue) { + this.$emit('changeDropdownData', newValue) + } + }, deep: true }, methods: { toggleDropdown() { @@ -91,8 +88,6 @@ } }, submitSelection() { - // 鍦ㄨ繖閲屽鐞嗘彁浜ら�夐」鐨勯�昏緫 - console.log("宸查�夋嫨鐨勯�夐」:", this.selectedOptions); // 閲嶇疆閫夐」骞堕殣钘忕‘璁ゆ寜閽� this.selectedOptions = []; this.showConfirmButton = false; @@ -102,6 +97,15 @@ }, filterOptions() { this.showDropdown = true; + }, + //鏆撮湶 + changeSelectData(value) { + this.selectedOptions = value + }, + handleChange(event) { + // 褰撻�変腑椤瑰彉鍖栨椂瑙﹀彂 + // 閫氱煡鐖剁粍浠舵柊鐨勯�変腑鍊� + this.$emit('changeDropdownData', event.target.value); }, }, }; @@ -121,6 +125,7 @@ right: -31%; top: -21%; } + .dropdown { min-width: 200px; position: relative; @@ -157,14 +162,16 @@ margin-right: 4px; margin-bottom: 4px; } + .selected-value .selected-value-txt { height: 24px; - display: inline-block; + display: inline-block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 80px; } + .selected-value .delete { margin-left: 4px; cursor: pointer; -- Gitblit v1.9.1