Vue+elementui 过滤条件

<template>
  <el-container>
    <el-main>
      <el-form :inline="true" :model="queryParams" class="demo-form-inline">
        <el-form-item label="名称:" prop="ProjectName">
          <el-input
            v-model="queryParams.ProjectName"
            placeholder="请输入名称"
            clearable
            @clear="clearInput()"
          />
        </el-form-item>
        <el-form-item label="城市:" prop="City">
          <el-input
            v-model="queryParams.City"
            placeholder="请输入城市"
            clearable
            @clear="clearInput()"
          />
        </el-form-item>
        <el-form-item label="时间:" prop="OpeningTime">
          <el-date-picker
            v-model="valueTime"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            @change="empty_querypro"
            @clear="clearInput()"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="queryitem()">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="tableList" border stripe highlight-current-row>
        <el-table-column prop="ProjectName" label="名称">
          <template slot-scope="scope">
            <span>{{ scope.row.ProjectName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="City" label="城市">
          <template slot-scope="scope">
            <span>{{ scope.row.City }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="OpeningTime" label="时间">
          <template slot-scope="scope">
            <span>{{ scope.row.OpeningTime }}</span>
          </template>
        </el-table-column>
      </el-table>
    </el-main>
  </el-container>
</template>
<script>
import { Queryproject } from '@/api/project'
export default {
  data() {
    return {
      queryParams: {
        current: 1,
        limit: 20,
        total: 0,
      },
      tableList: [],
      valueTime: ''
    }
  },
  created() {
    this.queryitem()
  },
  methods: {
    clearInput() {
      this.queryitem()
    },
    empty_querypro(val) {
      console.log('选择的时间', val)
      if (val != null && val !== undefined && val.length !== 0) {
        this.queryParams.BeginTime = val[0].replace(/-/gi, '')
        this.queryParams.EndTime = val[1].replace(/-/gi, '')
        console.log('开始时间', this.queryParams.BeginTime)
        console.log('结束时间', this.queryParams.EndTime)
      } else {
        this.queryParams.BeginTime = null
        this.queryParams.EndTime = null
      }
      // this.queryitem()
    },
    queryitem() {
      Queryproject(this.queryParams).then(response => {
        if (response.data.success) {
          this.queryParams.total = Number(JSON.parse(response.data.data).TotalSize)
          if (JSON.parse(response.data.data).RowCnt) {
            this.tableList = JSON.parse(response.data.data).Records
            console.log(this.tableList)
          }
        }
      })
    }
  }
}
</script>
<style scoped>
</style>

1.可通过名称城市或者时间通过点击‘搜索’按钮实现对于表格信息的过滤

2.替换表接口和相应字段即可

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
要在 Vue 中使用 ElementUI 表格进行搜索,你可以使用两种方法: 1. 使用 ElementUI 的 el-input 组件来实现搜索功能 在表格上方添加一个输入框,用户可以在其中输入搜索关键字,然后使用 JavaScript 过滤表格数据并更新表格。 HTML: ``` <template> <div> <el-input v-model="searchText" placeholder="请输入搜索关键字"></el-input> <el-table :data="tableData.filter(item => item.name.includes(searchText))"> <el-table-column prop="name" label="姓名"></el-table-column> <el-table-column prop="age" label="年龄"></el-table-column> </el-table> </div> </template> ``` JavaScript: ``` export default { data() { return { tableData: [ { name: '张三', age: 18 }, { name: '李四', age: 20 }, { name: '王五', age: 22 } ], searchText: '' }; } }; ``` 2. 使用 ElementUI 的 el-form 组件来实现搜索功能 这种方法可以将搜索关键字与其他筛选条件一起提交到后端进行处理,然后根据后端返回的数据来更新表格。 HTML: ``` <template> <div> <el-form :inline="true" :model="form"> <el-form-item label="姓名"> <el-input v-model="form.name"></el-input> </el-form-item> <el-form-item label="年龄"> <el-input v-model="form.age"></el-input> </el-form-item> <el-form-item> <el-button type="primary" @click="submitForm">搜索</el-button> </el-form-item> </el-form> <el-table :data="tableData"> <el-table-column prop="name" label="姓名"></el-table-column> <el-table-column prop="age" label="年龄"></el-table-column> </el-table> </div> </template> ``` JavaScript: ``` export default { data() { return { tableData: [], form: { name: '', age: '' } }; }, methods: { submitForm() { // 向后端提交搜索条件,并获取返回数据更新表格 } } }; ``` 以上是两种使用 ElementUI 表格进行搜索的方法,你可以根据自己的需求选择适合自己的方法。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值