简单的 前端模糊查询

<style scoped>

ul,

li {

padding: 0;

margin: 0;

list-style-type: none;

padding: 0;

box-sizing: border-box;

}

.outbox {

margin: 0 auto;

width: 200px;

height: 30px;

position: relative;

}

.input {

box-sizing: border-box;

width: 200px;

height: 30px;

}

.showList {

position: absolute;

width: 180px;

border: 1px solid #789;

}

.ulList {

width: 100%;

margin: 0;

height: 200px;

overflow: auto;

}

.liLIst {

margin: 0;

box-sizing: border-box;

width: 100%;

height: 25px;

line-height: 25px;

}

.liLIst:hover {

border: 1px solid #ccc;

background-color: #ccc;

}

</style>

 

<template>

<div class="hello">

<div class="outbox">

<input class="input" type="text" v-model="city.name" @keyup="search(city.name)" @focus="showList=true" >

<div v-show="showList">

<div class="showList" v-if="searchBox">

<ul class="ulList">

<li class="liLIst"

v-for="(a,index) in cityList "

:key= index :value="a.key"

@click="getName(a)"

>{{a.value}}</li>

</ul>

</div>

<div class="showList" v-if="!searchBox">

<ul class="ulList">

<li class="liLIst"

v-for="(a,index) in newcityList "

:key= index :value="a.key"

@click="getName(a)"

>{{a.value}}</li>

</ul>

</div>

</div>

</div>

</div>

</template>

 

<script>

// <searchinput

// :city='cityObj'

// :cityList="cityList">

// </searchinput>

 

// import dataList from '../assets/mock/mock'

export default {

name: "HelloWorld",

data() {

return {

showList:false,

searchBox:true,//显示那个盒子

// cityList: [],

newcityList:[],//查找出的新数组

};

},

props:{

cityList:{

type:Array,

default:[]

},

city: {

id: "",

name: ""

}

},

computed: {},

watch: {

"city.name": function(a) {

this.city.name = a;

},

"city.id": function(a) {

console.log(this.city)

a ? this.showList = false :''

}

},

methods: {

// 根据当前输入的字符 查找包含的对象

search(a) {

this.newcityList=[]

this.searchBox = false

this.cityList.forEach(city => {

let cityName = city.value.toString()

if(cityName.indexOf(a)!==-1){

this.newcityList.push(city)

// console.log( this.newcityList)

}

});

},

// 点击获取当前value

getName(a) {

this.city.name = a.value;

this.city.id = a.key

}

},

created() {

}

};

</script>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值