欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

vue搜索和vue模糊搜索代码实例

程序员文章站 2023-11-29 11:48:28
1、使用vue来实现一般搜索
&...

1、使用vue来实现一般搜索

<form action="" @submit="submitquery" class="all_two">
   <el-input v-model="input" placeholder="请输入内容" ref="search" style="width:300px;"></el-input>
</form>
<div class="all_three">
   <div v-for="item in this.$store.state.chufang.alldata">
      <div v-for="item1 in querydate(item.cabinet)" >
         <input type="checkbox" name="checkbox" value="checkbox" style="zoom:200%;" :checked="item1.checks==0? true:false">
         <span>{{item1.name}}</span>
      </div>
    </div>
</div
submitquery:function(){
  this.query = this.$refs.search.value.trim();
},
querydate:function(list){
   if (this.query === '') {
     return list
   } 
   return list.filter((item)=>{
     if(item.name.indexof(this.query) != -1){
      return item;
     }
   })
},

2、vue模糊搜索,原理都是一样的

<el-form :inline="true" :model="forminline" class="demo-form-inline mt15">
   <el-form-item>
     <el-input v-model="forminline.name" ref="search"  placeholder="姓名"></el-input>
   </el-form-item>
   <el-form-item>
      <el-input v-model="forminline.phone" ref="search1" placeholder="手机号"></el-input>
   </el-form-item>
   <el-form-item>
      <el-button type="primary" @click="onsubmit">筛选</el-button>
   </el-form-item>
 </el-form>
onsubmit() {
   this.query = this.$refs.search.value.trim();
   this.query1 = this.$refs.search1.value.trim();
},
querydate:function(list){
   if (this.query === '' && this.query1 === '') {
     return list
   } 
   else if (this.query !== '' && this.query1 === '') {
     return list.filter(item => {
       if (item.name.indexof(this.query) !== -1) {
         return item
        }
     })
    } 
    else if (this.query === '' && this.query1 !== '') {
     return list.filter(item => {
        if (item.mobile.indexof(this.query1) !== -1) {
          return item
         }
      })
    } 
    else if (this.query !== '' && this.query1 !== '') {
      return list.filter(item => {
        if (item.name.indexof(this.query) !== -1 && item.mobile.indexof(this.query1) !== -1) {
          return item
        }
      })
    }
},

以上所述是小编给大家介绍的vue搜索和vue模糊搜索详解整合,希望对大家有所帮助