搜索框模糊提示
HTML部分
<template>
<div class="content">
<input v-model="value" label="搜索" placeholder="请输入用户名" @input="searchchange" @focus="focuschange"
@blur="blurchange" />
<ul class="Newbox" v-if="Isshow">
<li v-for="(item,index) in newsListTow" :key="index">
{{item}}
</li>
</ul>
</div>
</template>
Js部分
<script>
export default {
data() {
return {
value: null,
newsList: [
'软件园三期B1栋', '软件园三期B2栋', '软件园三期B3栋',
'集美园三期B4栋', '集美园三期B5栋', '集美园三期B6栋', '集美园三期B7栋',
],
newsListTow: [],
Isshow: false
};
},
methods: {
searchchange() { //输入框时输入中事件
if (this.value == '') {
this.Isshow = false
} else {
this.newsListTow = [] //防止从复
this.newsList.forEach(item => {
if (item.indexOf(this.value) != -1) {
this.newsListTow.push(item)
}
})
this.Isshow = true}
},
focuschange() { //鼠标点击时焦点事件
if (this.value == '') {
this.Isshow = false
} else {
this.Isshow = true
this.newsListTow = []
}
},
blurchange() { //输入移除框事件
this.Isshow = false
},},
};
</script>
CSS 部分
<style>
input {
width: 320px;
height: 30px;
margin-top: 10px;
margin-left: 110px;
}.Newbox {
width: 300px;
height: auto;
border: 1px solid #ccc;
margin-left: 110px;
padding: 10px;
margin-top: 10px;
}.Newbox li {
font-size: 14px;
margin-bottom: 10px;
cursor: pointer;
}.Newbox li:hover {
color: darkgoldenrod;
}
</style>