Compare commits

..

No commits in common. "ac1dc62adc6d48f1fa9a36f61342cf2947947be8" and "a85a9ee17bf116a6fe56b858550335f8df6cde01" have entirely different histories.

2 changed files with 20 additions and 141 deletions

View File

@ -1,19 +1,21 @@
<template> <template>
<div class="search" id="search"> <view class="search" id="search">
<a-input v-model="valueInput" @input="searchInput" placeholder="请进行搜索"></a-input> <nut-input v-model="valueInput" @input="searchInput" placeholder="请进行搜索"></nut-input>
<div v-if="valueInput"> <view v-if="valueInput">
<ul> <ul>
<li v-for="item in searchResults" :key="item.id">{{item}}</li> <li v-for="item in searchResults" :key="item.id">{{item}}</li>
</ul> </ul>
</div> </view>
<div v-else > <view v-else >
没有找到相关结果 没有找到相关结果
</div> </view>
</div> </view>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {onMounted, ref,} from "vue"; import './index.scss'
import { ref} from "vue";
const valueInput = ref('') const valueInput = ref('')
// '','','','','','','','','',''
const list = ref([]) const list = ref([])
const dataList = ref([ const dataList = ref([
{ {
@ -64,7 +66,7 @@ const dataList = ref([
value:'明德小学' value:'明德小学'
},{ },{
id:12, id:12,
value:'希望小学', value:'希望小学'
} }
]) ])
const searchResults = ref([]) const searchResults = ref([])
@ -72,37 +74,21 @@ const searchInput = (e:any)=>{
valueInput.value = e.target.value valueInput.value = e.target.value
if (!valueInput.value) { if (!valueInput.value) {
searchResults.value = [] searchResults.value = []
return; return [];
}else{ }else{
dataList.value.map((item)=>{
return list.value.push(item.value)
})
searchResults.value = list.value.filter(item => searchResults.value = list.value.filter(item =>
item.toLowerCase().includes(valueInput.value.toLowerCase()) item.toLowerCase().includes(valueInput.value.toLowerCase())
); );
} }
// console.log(searchResults.value)
} }
onMounted(()=>{
dataList.value.map((item)=>{
return list.value.push(item.value)
})
})
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.search{
padding: 0 10px;
overflow: hidden;
border: 1px solid #4e71f2;
margin: 1px 5px;
border-radius: 10px;
width: 30%;
.ceShi{
height: 300px;
background: #ccc;
}
}
.nut-input{
padding: 20rpx 20rpx;
margin: 5px 0;
}
</style> </style>

View File

@ -1,114 +1,7 @@
<template> <template>
<div class="search" id="search"> <div style="margin: 100px auto;width: 500px">
<a-input v-model="valueInput" @input="searchInput" placeholder="请进行搜索"></a-input>
<div v-if="valueInput">
<ul>
<li v-for="item in searchResults" :key="item.id">{{item}}</li>
</ul>
</div> </div>
<div v-else >
没有找到相关结果
</div>
</div>
</template> </template>
<script setup lang="ts"> <script lang="ts" setup>
import {onMounted, ref,} from "vue";
const valueInput = ref('')
const list = ref([])
const dataList = ref([
{
id:0,
value:'齐家园'
},
{
id:1,
value:'刘德华'
},
{
id:2,
value:'张学友'
},{
id:3,
value:'黎明'
},
{
id:4,
value:'家具城'
},
{
id:5,
value:'左岸春天'
},
{
id:6,
value:'麦德龙商城'
},
{
id:7,
value:'世纪酒店'
},
{
id:8,
value:'四方小学'
},
{
id:9,
value:'海洋半岛'
},
{
id:10,
value:'育英小学'
},
{
id:11,
value:'明德小学'
},{
id:12,
value:'希望小学',
}
])
const searchResults = ref([])
const searchInput = (e:any)=>{
valueInput.value = e.target.value
if (!valueInput.value) {
searchResults.value = []
return;
}else{
searchResults.value = list.value.filter(item =>
item.toLowerCase().includes(valueInput.value.toLowerCase())
);
}
}
// watch(()=>valueInput.value,(value)=>{
// if(!value){
// searchResults.value = []
// }
// })
onMounted(()=>{
dataList.value.map((item)=>{
return list.value.push(item.value)
})
})
</script> </script>
<style scoped lang="scss">
.search{
padding: 0 10px;
overflow: hidden;
border: 1px solid #4e71f2;
margin: 1px 5px;
border-radius: 10px;
width: 30%;
.ceShi{
height: 300px;
background: #ccc;
}
}
.nut-input{
padding: 20rpx 20rpx;
margin: 5px 0;
}
</style>