Vue 模糊查询(按字段)

你的名字 2021-09-07 09:44 786阅读 0赞

根据人家的代码,对应改成自己的需要的功能
原参考地址:https://blog.csdn.net/zuorishu/article/details/86630097

  1. <!-- 设备分组 -->
  2. <template>
  3. <view class="content">
  4. <view class="search">
  5. <!--用了一个uview的u-search的小组件-->
  6. <u-search placeholder="搜索" shape="square" :show-action="true" bg-color="#fff" v-model="search"></u-search>
  7. </view>
  8. <view>
  9. <view class="grouping" v-for="(item,index) in items">
  10. <image src="../../../../static/img/home/grouping-icon.png" mode=""></image>
  11. <view class="grouping-nav-tit">
  12. <view class="grouping-nav">{
  13. {item.station_name}}</view>
  14. <view class="grouping-nav" style="font-size: 16px;">{
  15. {item.station_address}}</view>
  16. </view>
  17. <view class="grouping-nav-btn">
  18. <view class="button">照片</view>
  19. <view class="button">位置</view>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. data() {
  28. return {
  29. search: '',
  30. groupinglist: []
  31. }
  32. },
  33. onLoad() {
  34. this.getStationListByRelate()
  35. },
  36. computed: {
  37. getStationListByRelate() {
  38. this.$http.get('JiekouMing', {
  39. canshu: 35
  40. }).then(res => {
  41. this.groupinglist = res.data.data;
  42. console.log(this.groupinglist)
  43. })
  44. },
  45. items: function() {
  46. var _search = this.search;
  47. if (_search) {
  48. //不区分大小写处理
  49. var reg = new RegExp(_search,'name')
  50. //es6 filter过滤匹配,有则返回当前,无则返回所有
  51. return this.groupinglist.filter(function(e) {
  52. //匹配某个字段
  53. return e.station_name.match(reg);
  54. })
  55. };
  56. console.log(this.groupinglist)
  57. return this.groupinglist;
  58. }
  59. }
  60. }
  61. </script>
  62. <style> page {
  63. background-color: #f5f5f5;
  64. }
  65. .content {
  66. width: 90%;
  67. margin-left: 5%;
  68. }
  69. .search {
  70. width: 100%;
  71. height: 50px;
  72. display: flex;
  73. justify-content: center;
  74. align-items: center;
  75. padding: 5%;
  76. }
  77. .grouping {
  78. margin-top: 10px;
  79. display: flex;
  80. justify-content: flex-start;
  81. align-items: center;
  82. height: 80px;
  83. background-color: #fff;
  84. box-shadow: 2px 2px 1px #ccc;
  85. border-radius: 2px;
  86. }
  87. .grouping image {
  88. margin-left: 10px;
  89. width: 50px;
  90. height: 50px;
  91. }
  92. .grouping-nav-tit {
  93. width: 65%;
  94. }
  95. .grouping-nav {
  96. width: 100%;
  97. padding-left: 10px;
  98. font-size: 18px;
  99. line-height: 25px;
  100. overflow: hidden;
  101. /*超出部分隐藏*/
  102. text-overflow: ellipsis;
  103. /* 超出部分显示省略号 */
  104. white-space: nowrap;
  105. /*规定段落中的文本不进行换行 */
  106. }
  107. .grouping-nav-btn {
  108. display: flex;
  109. justify-content: center;
  110. flex-wrap: wrap;
  111. width: 20%;
  112. /* height: 60px; */
  113. }
  114. .button {
  115. margin-top: 10px;
  116. width: 50px;
  117. height: 23px;
  118. border-radius: 5px;
  119. text-align: center;
  120. line-height: 23px;
  121. background-color: #2E95FF;
  122. color: #FFFFFF;
  123. }
  124. </style>

发表评论

表情:
评论列表 (有 0 条评论,786人围观)

还没有评论,来说两句吧...

相关阅读