vue 中的通過搜索框進行數據過濾的過程


 1 <template>
 2  <div>
 3     <input type="text" v-model="searchId" placeholder="搜索">
 4     <table class="tab">
 5       <tr>
 6         <th>序號</th>
 7         <th>名字</th>
 8         <th>時間</th>
 9         <th>操作</th>
10       </tr>
11       <tr v-for="(item,index) in newlist" :key="index">
12         <td>{{item.id}}</td>
13         <td>{{item.name}}</td>
14         <td>{{item.ctime}}</td>
15         <td><a href="#" @click="dele(index)">刪除{{index}}</a></td>
16       </tr>
17    <!-- <tr v-if="list.length===0"><td colspan="4">已經沒有數據了,請添加數據吧 123</td></tr> -->
18     </table> 
19  </div>
20 </template>
21 
22 <script>
23  export default {
24    data () {
25      return {
26         searchId:"",
27         list:[
28          {id:1,name:"cc",ctime:new Date()},
29          {id:2,name:"zs",ctime:new Date()},
30          {id:3,name:"ss",ctime:new Date()}
31        ],
32      }
33    },
34    computed:{
35        newlist(){
36     //1. 常規做法
37     //     var that=this
38     //     function iscontainer(value){
39     //       return  value.name.indexOf(that.searchId)!==-1
40     //     }
41     //     var temlist=this.list.filter(iscontainer)
42     // iscontainer是一個函數,value就是list中的每一項的值,通過判斷是否包含來來過濾數據內容
43     //     return temlist
44     //    }
45     //2.es6做法
46         return this.list.filter(value=>value.name.indexOf(this.searchId)!==-1)  
47 
48         }
49    }
50 }
51 </script>
52 
53 <style>
54 
55  
56 </style>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM