uniapp 微信小程序 循环生成的input 实现输入历史功能 每个input有自己对应的输入历史

HTML

<view class="form-item-input" v-if="item.type=='text'">
	<input name="input" 
            autocomplete="on" 
            :placeholder="item.des ? item.des:'请输入'"
			v-model="item.value" 
            @focus="showHistory(item)"
			@input="findHistory"  
    />
	<!--历史记录!-->
<view  v-if="selectFilter.widgetName == item.widgetName" class="history" style="width: 100%;position: absolute;background: #FFF;border: 2rpx solid #ccc; z-index: 999;border-top: none;">
	<view 
		v-for="(history,index) in searchList"
		:key="index"
		v-if="item.widgetName == history.widgetName"
		@tap="historySearch(history)"	
		style="padding: 5rpx 20rpx"								
	>								
		{
   
   { history.value }}								
	</view>
</view>	
searchMsg(option) {
			// 存入缓存
	console.log(option)
	if(option != ''){
		try {
			 let value = uni.getStorageSync(this.contestId)
			 if(value){
			     // 最多缓存20条记录
			     this.searchList = JSON.parse(value).slice(0,20)
			   }
			  //去重
			  let index = this.searchList.indexOf(option)
			  if(index > -1){
			      this.searchList.splice(index,1)
			  }
		      this.searchList.slice(0,this.searchList.length)
			  this.searchList = option
			  uni.setStorageSync(this.contestId, JSON.stringify(this.searchList))
			 }catch(e){
			      console.log(e)
			    }
			    // 清空searchList
			  this.clearList()
	}
	},

猜你喜欢

转载自blog.csdn.net/weixin_60404020/article/details/135369089