当前位置:主页 > 动态 >

uniapp如何实现增加提示的功能

时间:2020-12-19 16:11:42

  uniapp增加提示的实现方法:首先判断input并获取焦点;然后通过接口获取数据,并做前端模拟处理;接着设置input框的change事件;最后设置点击事件,并实现搜索点击即可。

  本教程操作环境:Windows7系统、uni-app2.5.1版本,该方法适用于所有品牌电脑。

  (免费):uni-app开发教程

  uniapp实现一个搜索加提示功能(含传参等)

  

 

  先看代码,复制使用即可,我已帮您考虑到使用v-for循环或者其他可能带来的问题。(这里您安装插件使用scss)您将看到以下效果。

  <template> <view class="box"> <input type="text" @input="GetValue" class="S-input" :placeholder="placeholder" @focus="ShowValue"> <!-- 判断input获取焦点同时后台给到了数据 --> <view class="InputList" v-show="isValue && SearchList.length"> <view v-for="item in SearchList" :key="item.id" @click="SetValue(item.title)" class="listSon"> {{item.title}} </view> </view> </view></template><script> export default { data() { return { Value: '', //搜索内容 placeholder: '请输入搜索内容', //提示 isValue: false, //文字框是否显示 SearchList: [] } }, methods: { ShowValue() { this.isValue = !this.isValue if (this.isValue) { //如果获取到了焦点 this.getList() } else { //失去焦点 清空数据 } }, getList(value) { //这一步是获取数据 您可以通过接口获取 这里做前端模拟处理 // 需要和后台协商没有数据时候传递默认的几条 // axios.get('/getList?value='+value).then(res=>{ //请求案例 // this.SearchList = res.data.data // }) if (!value) { let arr = [{ id: 1, title: "我是搜索信息1" }, { id: 2, title: "我是搜索信息2" }, { id: 3, title: "我是搜索信息3" }, { id: 4, title: "我是搜索信息4" }, { id: 5, title: "我是搜索信息5" }, ] this.SearchList = arr } else { this.getList() } }, GetValue(event) { //input框的change事件 console.log('当前输入' + event.detail.value) // 有值就获取 没有就让他为空 event.detail.value ? this.Value = event.detail.value : this.Value = '' event.detail.value ? this.getList(this.Value) : this.getList(this.Value) }, SetValue(value) { //点击事件 搜索点击这一条 console.log('搜索信息为' + value) this.Value = value this.placeholder = value this.SearchList = [] this.isValue = !this.isValue // 拿到数据 做页面跳转操作比如 // uni.navigateTo({ // url:"../cart/cart" // }) } }, onLoad() {} }</script><style lang="scss"> $max:100%; .box { width: $max; padding: 10 30rpx; //上下10 左右utList { position: absolute; width: 690rpx; height: auto; min-height: 100rpx; top: 74rpx; border: 1rpx solid #409EFF; border-radius: 5rpx; padding: 10rpx; .listSon { height: 50rpx; line-height: 50rpx; font-size: 32rpx; text-indent:1em; } .listSon:nth-of-type(even){ background: #f7f7f7; } } }</style>

  附加和可能出现的有用信息已添加注释
 

  其他有关uniapp的疑问或者此方法不理解的地方您可留言,我会尽快回复并帮您解决。

热点推荐
1 BIT称贪婪与恐惧指数改善,比特币具备反

消息,据A早期发行in监测,BIT表示,尽管市场空头仓位较重且交易量低迷,但其贪婪与恐惧指...

2 Solana链上非USDCUSDT稳定币供应量达48.1亿美

消息,据Solanafloor监测,Solana链上非USDC/USDT稳定币供应量达到48.1亿美元,创下历史新高,由U...

3 海湾基石石油公司因安全局势变化暂时停

消息,海湾基石石油公司宣布,鉴于地区安全局势变化,作为安全防范措施,已暂时停产。公...

4 LBBW:外国私营投资者再次成为美国国债的

消息,LBBW高级固定收益分析师Elmar Voelker在一份报告中表示,来自私营部门的外国投资者显然已...

5 阿里巴巴推出Qwen3.8 Max AI模型,全球排名

消息,阿里巴巴近日推出了Qwen3.8 Max AI模型,声称在全球范围内仅次于Anthropic的Fable 5。这一进...

6 英国将伊朗革命卫队纳入国家安全法,最

消息,英国自7月17日起将伊朗伊斯兰革命卫队纳入《2023年国家安全法》附表6a。相关个人或企...

7 OKX宣布上线KAITOUSD UM(X

消息,OKX宣布将KAITOUSD UM添加到多个服务中,包括多项交易服务,预计于2026年07月20日19:00正式...

8 Jason Yanowitz:全球约有800家加密流动性基

消息,据A早期发行in监测,知名交易员Ansem询问加密领域流动性基金数量及规模,Blockworks联合...

9 比特币开发者推出BIP

消息,比特币开发者近日推出BIP-361提案,旨在保护钱包免受未来量子计算风险。该提案将阻止...

10 Coinbase CEO:AI或长期吸引比特币挖矿能源

消息,Coinbase CEO Brian Armstrong在X平台回应Chamath Palihapitiya关于比特币市场变化的观点。他表示,...

成都来彰科技 蜀ICP备2025134723号-1

资讯来源互联网,如有版权问题请联系管理员删除。