IT俱乐部 JavaScript VUE el-table列表搜索功能纯前端实现方法

VUE el-table列表搜索功能纯前端实现方法

背景:

对el-table数据进行搜索筛选,但是不想调取接口,纯前端实现

直接看代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<div class="project-container">
    <div class="table">
       
</div>
  </div>
 
import Vue from 'vue'
 
import SearchInputVue from '@/components/Input/SearchInput.vue'
import DefectList from './components/DefectList.vue'
// import Info from '@/mock.json'
import API from '@/api'
import { warn } from '@/utils/common'
 
export default Vue.extend({
  name: 'Index',
  components: {
    SearchInputVue,
    DefectList
    // TypeIcon
  },
  data() {
    return {
      defectList: [],
      filterDefectList: [],
      placeholderWords: '搜索缺陷',
      keyword: '',
      fetchListPageData: {
        total: 0,
        page: 1,
        pageSize: 10
      }
    }
  },
  watch: {
    keyword(newVal) {
      const keyVal = newVal.replace(' ', '')
      this.filterDefectList = keyVal ? this.defectList.filter(item => item.title.includes(keyVal)) : this.defectList
    }
  },
  created() {
    this.getDefectList()
  },
  methods: {
    async getDefectList() {
      try {
        const res = await API.Defect.defectListData({
          keyword: '',
          page: this.fetchListPageData.page,
          pageSize: this.fetchListPageData.pageSize
        })
        this.defectList = res.data.list
        this.fetchListPageData.total = res.data.total
      } catch (error) {
        warn(error, true)
      }
    },
    pageChange(current: number) {
      this.fetchListPageData.page = current
      this.getDefectList()
    }
  }
})
 
.project-container {
  .project-name {
    img {
      position: relative;
      top: 3px;
    }
  }
}

searchInput.vue

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<img decoding="async" class="search-icon" src="@/image/search.svg" alt="search">
export default {
  name: 'SearchInput',
  props: {
    placeholder: {
      type: String,
      default: '请输入要搜索的内容'
    },
    keyword: {
      type: String,
      default: ''
    }
  },
  computed: {
    _keyword: {
      set: function (val) {
        this.$emit('update:keyword', val)
      },
      get: function () {
        return this.keyword
      }
    }
  }
}
 
.search {
  width: auto;
 
  /deep/ .el-input__prefix {
    margin-left: 10px;
    line-height: 40px;
  }
 
  /deep/ .el-input__inner {
    padding-left: 54px;
    width: 305px;
    // height: 56px;
    border-radius: 5px;
    background-color: rgba(34, 37, 41, 1);
    border: 0.5px solid rgba(255, 255, 255, 0.1);
    font-weight: normal;
    font-size: 16px;
    line-height: 32px;
    color: #fff;
  }
 
  /deep/ .el-input__suffix {
    .el-input__suffix-inner {
      border-color: none;
      position: relative;
 
      .el-icon-circle-close:before {
        content: 'e6db' !important;
        font-size: 24px;
        color: #387DFF;
        right: 20px;
        top: -7px;
        position: absolute;
      }
    }
  }
}
 
.search-icon {
  vertical-align: middle;
  line-height: 40px;
}

总结 

到此这篇关于VUE el-table列表搜索功能纯前端实现的文章就介绍到这了,更多相关VUE el-table列表搜索内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章希望大家以后多多支持IT俱乐部!

本文收集自网络,不代表IT俱乐部立场,转载请注明出处。https://www.2it.club/navsub/js/13086.html
上一篇
下一篇
联系我们

联系我们

在线咨询: QQ交谈

邮箱: 1120393934@qq.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部