美文网首页
基于elementUI的前端搜索

基于elementUI的前端搜索

作者: winterzy | 来源:发表于2018-11-10 20:05 被阅读0次

本周在研究elementui框架,发现基于它的搜索非常便捷好用,在此记录。

例如要搜索一个table内的关键字

<el-input v-model="peopleSearch" placeholder="请输入">

<el-table :data="peopleMange"> 

</el-table>


data() {

      return {

        peopleSearch: ''    //绑定搜索内容

      }

},


computed: {

      // 人员搜索

      peopleMange() {

        const peopleSearch = this.peopleSearch;   //这里要定义

        if (peopleSearch) {

          return this.tableData.filter(data => {

            return Object.keys(data).some(key => {

              return String(data[key]).toLowerCase().indexOf(peopleSearch) > -1

            })

          })

        }

        return this.tableData;

      }

    },

关键点:

1:table的data要绑定你定义的那个方法

2:input的v-model绑定自定义的变量,此变量在之前定义的方法中做判断用

相关文章

网友评论

      本文标题:基于elementUI的前端搜索

      本文链接:https://www.haomeiwen.com/subject/cvktfqtx.html