当前位置:Gxlcms > JavaScript > vuejs通过filterBy、orderBy实现搜索筛选、降序排序数据

vuejs通过filterBy、orderBy实现搜索筛选、降序排序数据

时间:2021-07-01 10:21:17 帮助过:47人阅读

直接贴代码了:

先上输入前的样子:

  1. <style>
  2. #example{margin:100px auto;width:600px;}
  3. .show{margin:10px;}
  4. #searchText{display: block;margin:0 auto 10px;height:24px;line-height: 24px;width:200px;}
  5. .content ul li{text-align: center;}
  6. .content ul li span{display: inline-block;width:150px;font-size:15px;color:#000;}
  7. </style>
  8. </head>
  9. <body>
  10. <div id="example">
  11. <input type="text" id="searchText" placeholder="搜索id或者姓名" v-model="searchData"/>
  12. <div class="content">
  13. <ul>
  14. <li v-for="item in items | filterBy searchData in 'id' 'name' | orderBy 'name' '-1'">
  15. <span>{{item.id}}</span>
  16. <span>{{item.name}}</span>
  17. <span>{{item.time}}</span>
  18. </li>
  19. </ul>
  20. </div>
  21. </div>
  22. <script>
  23. var example1 = new Vue({
  24. el: '#example',
  25. data: {
  26. searchData:'',
  27. items: [
  28. {id:'1008',name:'涛涛',time:'20170207'},
  29. {id:'1098',name:'合同',time:'20170213'},
  30. {id:'1107',name:'晓丽',time:'20170304'},
  31. {id:'1004',name:'小兰',time:'20170112'},
  32. {id:'1102',name:'财务',time:'20170203'},
  33. {id:'1108',name:'哈哈',time:'20170208'},
  34. {id:'1345',name:'测试',time:'20170201'},
  35. ]
  36. },
  37. ready:function(){
  38. },
  39. watch:{
  40. items:{
  41. handler:function(val,oldval){
  42. },
  43. deep:true
  44. }
  45. },
  46. methods:{
  47. }
  48. })
  49. </script>

当在输入框中输入'合同',得到结果如图:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。 

人气教程排行