<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="root">
<input type="text" placeholder="请输入要查询的字" v-model="keyword"> <button @click="search()">查询</button>
<ul>
<li v-for="(item,i) in filName" >{{item}}</li>
</ul>
</div>
<script>
new Vue({
el:'#root',
data:{
name:['张三','李四','王五','赵六'],
filName:[],
keyword:''
},
watch:{
keyword:{
immediate:true,
handler(val){
console.log(val)
this.filName = this.name.filter((p)=>{
return p.indexOf(val) !== -1
})
}
}
}
})
</script>
</body>
</html>
vue 过滤器
最新推荐文章于 2024-01-21 16:42:07 发布