国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

uni-app下拉框 可實(shí)現(xiàn)輸入下拉框 搜索+選擇組合框功能

這篇具有很好參考價值的文章主要介紹了uni-app下拉框 可實(shí)現(xiàn)輸入下拉框 搜索+選擇組合框功能。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

uni-app下拉框 可輸入下拉框 搜索+選擇組合框功能

效果圖

uni-app下拉框 可實(shí)現(xiàn)輸入下拉框 搜索+選擇組合框功能
uni-app下拉框 可實(shí)現(xiàn)輸入下拉框 搜索+選擇組合框功能
插件示例地址文章來源地址http://www.zghlxwxcb.cn/news/detail-513380.html

https://ext.dcloud.net.cn/plugin?id=3756
<!-- 頁面添加該標(biāo)簽 -->
<template>
    <view>
		<combox-search label="選擇職位:" labelWidth="130px" emptyTips="無匹配選項" :isJSON="true" :keyName="keyName"
			placeholder="請選擇職位" :candidates="zhiweiList" @getValue="getValue"></combox-search>
	</view>		
</template>

<script>
<!-- 引入該vue文件 -->
	import combox_Searchfrom "@/pages/components/cuihai-combox/cuihai-combox.vue"
	export default {
		components: {
			combox_Search 
		},
		data() {
			return {
				keyName: 'keyName',
				form: {
					
					zhiweiId: '', //職位id
					
				},
				zhiweiList: [], //職位
				
			}
		},
		onLoad() {
			this.getzhiweiList();
		
		},
		methods: {
			getValue(e) {
				console.log(e)
				this.form.zhiweiId= e.zhiweiId
			},
			onchange(e) {
				const value = e.detail.value
			},
			goBack() {
				uni.navigateTo({
					url: '/pages/menu/menu'
				})
			},
			changeLog(e) {},
			//查詢職位
			getzhiweiList() {
				//查詢方法接口
			},
		}

	}
</script>
//下載后并在項目中添加該文件
<template>
	<view class="uni-combox">
		<view v-if="label" class="uni-combox__label" :style="labelStyle">
			<text>{{label}}</text>
		</view>
		<view class="uni-combox__input-box">
			<input class="uni-combox__input" style="margin-left: -14px;" type="text" :placeholder="placeholder" :disabled="isDisabled" v-model="inputVal"
			 @input="onInput" @focus="onFocus" @blur="onBlur" />
			 <!--自測真機(jī)測試可以使用清除按鈕 -->
			<icon type="clear" size="10" @tap="clearInputValue" v-if="!isDisabled" />
			<!-- <uni-icons class="uni-combox__input-arrow" type="arrowdown" size="14" @click="toggleSelector"></uni-icons> -->
			<view class="uni-combox__selector" v-if="showSelector">
				<scroll-view scroll-y="true" class="uni-combox__selector-scroll">
					<view class="uni-combox__selector-empty" v-if="filterCandidatesLength === 0">
						<text>{{emptyTips}}</text>
					</view>
					<view class="uni-combox__selector-item" v-for="(item,index) in filterCandidates" :key="index" @click="onSelectorClick(item)"
					 :style="isCheck(index)?'color:'+selectColor+';background-color:'+selectBgColor+';':'color:'+color+';'">
						<text>{{isJSON?item[keyName]:item}}</text>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>

<script>
	/**
	 * Combox 組合輸入框
	 * @description 組合輸入框一般用于既可以輸入也可以選擇的場景
	 * @property {String} label 左側(cè)文字
	 * @property {String} labelWidth 左側(cè)內(nèi)容寬度
	 * @property {String} placeholder 輸入框占位符
	 * @property {Array} candidates 候選項列表
	 * @property {String} emptyTips 篩選結(jié)果為空時顯示的文字
	 * @property {String} value 單選時組合框的初始值
	 * @property {Array} initValue 多選時組合框的初始值(下標(biāo)集合)
	 * @property {String} keyName json數(shù)組顯示的字段值
	 * @property {Boolean} isJSON 是否是json數(shù)組,默認(rèn)不是
	 * @property {Boolean} isDisabled 是否是禁用輸入,默認(rèn)不禁用
	 * @property {Boolean} isCheckBox 是否是多選,默認(rèn)不是,多選時不能輸入查詢
	 * @property {String} color 默認(rèn)字體顏色,默認(rèn)#000000
	 * @property {String} selectColor 選中字體顏色,默認(rèn)#0081ff
	 * @property {String} selectBgColor 選中背景顏色,默認(rèn)#e8e8e8
	 */
	export default {
		name: 'comboxSearch',
		props: {
			label: {
				type: String,
				default: ''
			},
			labelWidth: {
				type: String,
				default: 'auto'
			},
			placeholder: {
				type: String,
				default: ''
			},
			candidates: {
				type: Array,
				default () {
					return []
				}
			},
			emptyTips: {
				type: String,
				default: '無匹配項'
			},
			value: {
				type: String,
				default: ''
			},
			initValue: {
				type: Array,
				default: null
			},
			keyName: {
				type: String,
				default: ''
			},
			isJSON: {
				type: Boolean,
				default: false
			},
			isDisabled: {
				type: Boolean,
				default: false
			},
			isCheckBox: {
				type: Boolean,
				default: false
			},
			color: {
				default: "#000000",
				type: String
			},
			selectColor: {
				default: "#0081ff",
				type: String
			},
			selectBgColor: {
				default: "#e8e8e8",
				type: String
			}
		},
		data() {
			return {
				showSelector: false,
				inputVal: '',
				arrays: [],
				gid: `sm-org-dropDown-${(new Date()).getTime()}${Math.random()}`
			}
		},
		computed: {
			labelStyle() {
				if (this.labelWidth === 'auto') {
					return {}
				}
				return {
					width: this.labelWidth
					//width: 130
				}
			},
			filterCandidates() {
				if (!this.isDisabled) {
					if (this.isJSON) {
						let index = 0;
						return this.candidates.filter((item) => {
							item.index = index;
							index++;
							return item[this.keyName].indexOf(this.inputVal) > -1
						})
					} else {
						return this.candidates.filter((item) => {
							return item.indexOf(this.inputVal) > -1
						})
					}
				} else {
					if (this.isJSON) {
						let index = 0;
						return this.candidates.filter((item) => {
							item.index = index;
							index++;
							return item[this.keyName] != undefined;
						})
					} else {
						return this.candidates
					}
				}
			},
			filterCandidatesLength() {
				return this.filterCandidates.length
			}
		},
		created() {
			if (this.initValue != null) {
				this.arrays = this.initValue;
				this.inputVal = this.getInpuevals();
			}
			//在created的時候,給子組件放置一個監(jiān)聽,這個時候只是監(jiān)聽器被建立,此時這段代碼不會生效
			//uni.$on接收一個sm-org-dropDown-show的廣播
			uni.$on('sm-org-dropDown-show', (targetId) => {
				//接收廣播,當(dāng)該組件處于下拉框被打開的狀態(tài),并且跟下一個被點(diǎn)擊的下拉框的gid不同時,將該組件的下拉框關(guān)閉,產(chǎn)生一個互斥效果。
				if (this.showSelector && this.gid != targetId) {
					this.showSelector = false
				}
			})
		},
		//當(dāng)子組件銷毀的時候,將建立的監(jiān)聽銷毀,這里不會影響代碼效果,但是在多次反復(fù)引用組件時,會在根節(jié)點(diǎn)定義越來越多的監(jiān)聽,長此以往影響性能,所以在不用的時候及時銷毀,養(yǎng)成好習(xí)慣
		beforeDestroy() {
			uni.$off('sm-org-dropDown-show')
		},
		watch: {
			value: {
				handler(newVal) {
					this.inputVal = newVal
				},
				immediate: true
			}
		},
		methods: {
			toggleSelector() {
				this.showSelector = !this.showSelector
				if (this.showSelector) {
					uni.$emit('sm-org-dropDown-show', this.gid)
				}
			},
			onFocus() {
				this.showSelector = true;
				uni.$emit('sm-org-dropDown-show', this.gid)
			},
			onBlur() {
				/* setTimeout(() => {
					this.showSelector = false;
				}, 50) */
			},
			onSelectorClick(index) {
				var itemPlus = index
				var items = index.id
				index = index.index
				if (this.isCheckBox) {
					let flag = this.arrays.indexOf(index);
					if (flag != -1) {
						let x = (this.arrays || []).findIndex((item) => item === index)
						this.arrays.splice(x, 1);
					} else {
						this.arrays.push(index);
					}
					this.inputVal = this.getInpuevals();
					if (this.isJSON) {
						this.$emit('getValue', this.arrays);
					} else {
						this.$emit('getValue', this.trimSpace(this.inputVal.split(" ")));
					}
				} else {
					this.showSelector = false
					if (this.isJSON) {
						this.$emit('getValue', itemPlus);
						//循環(huán)根據(jù)頁面數(shù)據(jù)傳入的數(shù)據(jù)下標(biāo)獲取搜索時的名稱跟id  并展示
						for (var i = 0; i < this.filterCandidates.length; i++){
							if(this.filterCandidates[i].index == index) {
								this.inputVal = this.filterCandidates[i].name;
							}
							
						}
					} else {
						this.$emit('getValue', this.filterCandidates[index]);
						this.inputVal = this.filterCandidates[index]
					}
				}
			},
			trimSpace(array) {
				for (var i = 0; i < array.length; i++) {
					if (array[i] == "") {
						array.splice(i, 1);
						i = i - 1;
					}
				}
				return array;
			},
			onInput() {
				setTimeout(() => {
					this.$emit('input', this.inputVal)
				})
			},
			clearInputValue() {
				this.inputVal = "";
				this.showSelector = false;
			},
			getInpuevals() {
				if (this.arrays.length == 0) {
					this.inputVal = "";
				} else {
					this.arrays.sort(function(a, b) {
						return a - b
					})
					this.inputVal = "";
					if (this.isJSON) {
						this.arrays.forEach(v => {
							this.inputVal += this.candidates[v][this.keyName] + " ";
						});
					} else {
						this.arrays.forEach(v => {
							this.inputVal += this.candidates[v] + " ";
						});
					}
				}
				return this.inputVal;
			},
			isCheck(index) {
				
				return this.arrays.indexOf(index) != -1;
			}
		}
	}
</script>

到了這里,關(guān)于uni-app下拉框 可實(shí)現(xiàn)輸入下拉框 搜索+選擇組合框功能的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • uni-app-使用tkiTree組件實(shí)現(xiàn)樹形結(jié)構(gòu)選擇

    uni-app-使用tkiTree組件實(shí)現(xiàn)樹形結(jié)構(gòu)選擇

    前言 在實(shí)際開發(fā)中我們經(jīng)常遇見樹結(jié)構(gòu)-比如樓層區(qū)域-組織架構(gòu)-部門崗位-系統(tǒng)類型等情況 往往需要把這個樹結(jié)構(gòu)當(dāng)成條件來查詢數(shù)據(jù),在PC端可以使用Tree,table,Treeselect等組件展示 在uni-app的內(nèi)置組件中似乎沒有提供這樣組件來展示,但是是有第三方包tkiTree組件來解決這個

    2024年02月14日
    瀏覽(68)
  • uni-app頂部下拉舒心

    操作步驟 基于 scroll-view 組件實(shí)現(xiàn)下拉刷新,需要通過以下方式來實(shí)現(xiàn)下拉刷新的功能。 配置 refresher-enabled 屬性,開啟下拉刷新交互 監(jiān)聽 @refresherrefresh 事件,判斷用戶是否執(zhí)行了下拉操作 配置 refresher-triggered 屬性,關(guān)閉下拉狀態(tài)

    2024年01月24日
    瀏覽(35)
  • uni-app 自定義下拉框

    uni-app 自定義下拉框

    如圖: ? ? html: view class=\\\"row-item\\\" view class=\\\"lable-tit\\\"性別:/view view class=\\\"selected-all\\\" view class=\\\"drop-down-box\\\" @click=\\\"btnShowHideClick\\\" text class=\\\"dropdown-content\\\"{{choiceContent}}/text image class=\\\"dropdown-icon\\\" src=\\\"/static/down.png\\\" mode=\\\"widthFix\\\"/image /view? view class=\\\"dialog-view\\\" v-if=\\\"isShowChoice\\\" text :class=\\\"choiceI

    2023年04月19日
    瀏覽(25)
  • uni-app中select下拉菜單

    uni-app中select下拉菜單

    select-lay - DCloud 插件市場

    2024年02月12日
    瀏覽(29)
  • uni-app在app端設(shè)置下拉刷新不生效

    下拉刷新這個問題,查了老半天。 我這只小菜雞,完全不知道view和scroll-view是不一樣的! 按照官網(wǎng)的方式, 1. 在 pages.json 里,找到的當(dāng)前頁面的pages節(jié)點(diǎn),并在 style 選項中開啟 enablePullDownRefresh: true 2. 在頁面中使用uni.startPullDownRefresh();以及uni.stopPullDownRefresh(); 可是可是,我

    2024年02月11日
    瀏覽(24)
  • 前端vue uni-app仿美團(tuán)下拉框下拉篩選組件

    前端vue uni-app仿美團(tuán)下拉框下拉篩選組件

    在前端Web開發(fā)中,下拉篩選功能是一種非常常見的交互方式,它可以幫助用戶快速選擇所需的選項。本文將介紹如何利用Vue.js和uni-app框架來實(shí)現(xiàn)一個高效的下拉篩選功能。通過使用這兩個強(qiáng)大的前端框架,我們可以輕松地創(chuàng)建具有響應(yīng)式用戶操作的下拉篩選組件。 首先,我

    2024年02月09日
    瀏覽(25)
  • 【Uni-App】uniapp使用uview實(shí)現(xiàn)彈出鍵盤輸入密碼/驗(yàn)證碼功能

    【Uni-App】uniapp使用uview實(shí)現(xiàn)彈出鍵盤輸入密碼/驗(yàn)證碼功能

    組件使用的是uview組件,Keyboard 鍵盤和MessageInput 驗(yàn)證碼輸入兩個組件配合使用。 通過mode參數(shù)定義鍵盤的類型,v-model綁定一個值為布爾值的變量,我綁定的是showKeyboard變量,控制鍵盤的彈出與收起; mode = number (默認(rèn)值)為數(shù)字鍵盤,此時頂部工具條中間的提示文字為\\\"數(shù)字鍵盤

    2023年04月16日
    瀏覽(95)
  • uni-app封裝省市區(qū)下拉組件(后臺獲取數(shù)據(jù))

    一.后臺數(shù)據(jù)格式 ?PROCINCE:[{itemName:\\\'\\\',itemValue:\\\'\\\'}] CITY:[{itemName:\\\'\\\',itemValue}] AREA:[{itemName:\\\'\\\',itemValue}] 前端將地址數(shù)據(jù)緩存在了pinia中 前端主要使用picker進(jìn)行勾選 二.代碼

    2024年02月12日
    瀏覽(27)
  • uni-app uni-ui 微信小程序 uni-datetime-picker 時間選擇組件設(shè)置start和end屬性,實(shí)現(xiàn)時間選擇限制

    uni-app uni-ui 微信小程序 uni-datetime-picker 時間選擇組件設(shè)置start和end屬性,實(shí)現(xiàn)時間選擇限制

    ?效果如圖,先選擇開始日期,完成日期需要在開始日期之后,先選擇完成日期,開始日期需要在完成日期之前 需要用到uni-datetime-picker官方的三個屬性? 代碼如下 這樣一個能夠限制選定范圍的組件就ok了! ? ?

    2024年02月11日
    瀏覽(93)
  • uni-app日期選擇器

    uni-app日期選擇器

    寫個簡單的日期選擇器,還沒搞樣式,所以有點(diǎn)丑 大概長這樣吧 首先是這個picker選擇器,mode選擇日期,end是寫一個范圍前日期,:end就是這個日期是動態(tài)變化的,還有change函數(shù) 然后是腳本,就默認(rèn)顯示當(dāng)前日期,設(shè)計最后范圍日期為今日日期,再有一個事件函數(shù)

    2024年02月12日
    瀏覽(94)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包