美文网首页
搜索查询

搜索查询

作者: 阳光之城alt | 来源:发表于2018-07-06 16:50 被阅读0次
image.png
<template>
    <div>
        <div class="seader">
            <input 
                v-model="keyword"
                class="search-input" 
                type="text" 
                placeholder="请输入你想去的城市"
            />
            <div class="serch-content" ref="seck"  v-show="keyword">
                <ul>
                    <li class="search-item border-bottom" v-for="item of list" 
                        :key="item.id" @click="handleclick(item.name)"
                        
                         >{{item.name}}</li>
                    <li class="search-item border-bottom " v-show="haslist">
                        没有找到匹配数据
                    </li>
                
                
                </ul>
            </div>
        </div>
    </div>
</template>

<script>
import bscroll from 'better-scroll'
export default {
    name:'seader',
    props:{
     aases:Object
    },
    data(){
        return{
            keyword:'',
            list:[],
            timer:null
        }
    },
    methods:{
        handleclick(city){
             //修改 $store.state.city 时 必须使用 dispatch 方法
            // this.$store.commit('changecity',city) 简单没有批量的操作commit
            this.$store.dispatch('changecity',city)
            this.$router.push('/')
        }
    },

    computed:{
        haslist(){
            return !this.list.length
        }

    },
    watch:{
        keyword () {    
            console.log(111)
            if(this.timer){ //搜索节流
                 clearTimeout(this.timer)
             }
             if(!this.keyword){ //清空搜索记录
                 this.list=[]
                 return
             }
               this.timer=setTimeout(()=>{
                   const result=[]
                   for(let i in this.aases) { //获取拼音和汉字
                       this.aases[i].forEach((value) => {//判断是否正确
                           if(value.spell.indexOf(this.keyword)>-1||
                              value.name.indexOf(this.keyword)>-1){
                                  result.push(value)
                            }
                        })
                   }
                   this.list=result
               },100)
            }
    },
    mounted() {
        this.scroll=new bscroll(this.$refs.seck)
    },
    
    }
</script>


<style lang="stylus" scoped>
       @import '~styles/varibles.styl'  
        .seader
            height .72rem
            padding 0 .1rem
            background $bgcolor
            .search-input
                box-sizing border-box 
                height .62rem
                line-height .62rem
                width 100%
                text-align center
                border-radius .06rem
                padding 0 .1rem
                color #666
            .serch-content
                position absolute
                overflow hidden
                top 1.58rem
                left 0
                right 0
                bottom 0
                background #eee
                z-index 1
                .search-item
                    line-height .62rem
                    padding-left .2rem
                    background #ffffff
                    clear #666
</style>

相关文章

  • 2020-03-01

    第7章 商品搜索 学习目标 根据搜索关键字查询 条件筛选 规格过滤 价格区间搜索 分页查询 排序查询 高亮查询 1...

  • 端口常用命令

    查询 IP 地址 外网地址查询 在百度搜索框中搜索【IP地址查询】 内网地址查询:Windows 查询 Mac 查...

  • 搜索查询

  • IPFS、Filecoin趋势热度榜

    IPFS、Filecoin趋势热度榜 Filecoin搜索结果 相关查询 (搜索您的字词的用户还搜索了这些查询。您...

  • ES 全文搜索

    ES 全文搜索 全文搜索 使用了match查询的多词查询只是简单地将生成的term查询包含在了一个bool查询中。...

  • 史上最全的ElasticSearch系列之基础(二)

    查询 空搜索 最基本的搜索API表单是空搜索(empty search),它没有指定任何的查询条件,只返回集群索引...

  • 阿里云专家全文搜索讲解

    搜索需求分析: 分词、全文检索 字符串模糊查询 相似查询 比如查询地址,比如搜索的问题,内部的知识库 任意...

  • 日志查询之搜索查询

    搜索与关键字"docker"有关的日志 1.tail -f 日志文件|grep "docker" 2.vi 日志文...

  • 07_Lucene搜索

    搜索 对要搜索的信息创建Query查询对象,Lucene会根据Query查询对象生成最终的查询语法,类似关系数据库...

  • NSPredicate 查询、搜索

    网址:http://blog.csdn.net/long11995563/article/details/9399...

网友评论

      本文标题:搜索查询

      本文链接:https://www.haomeiwen.com/subject/spdbuftx.html