【Vue入门实践3】不调后端接口==>el-table单纯前端实现查询和重置功能==>【el-table组件使用】表格静态前端筛选、查询重置功能


// 表格过滤

filterHandler(value, row, column) {

  const property = column["property"];

  return row[property] === value;

},



三、前端假查询重置功能

===========



1\. el-form表单

-------------



 <el-form-item label="设备名称:">

        <el-input

          v-model="formInline1.name"

          placeholder="请输入"

          style="height: 32px"

     ></el-input>

</el-form-item>

<el-form-item>

   <el-button-group>

          <el-button @click="reset1">重置</el-button>

          <el-button type="primary" @click="search1">查询</el-button>

   </

真题解析、进阶学习笔记、最新讲解视频、实战项目源码、学习路线大纲
详情关注公中号【编程进阶路】

el-button-group>

</el-form-item>
  <div class="title-name">报表详情:</div>

  <div class="title-refresh" @click="getPerimeterData1">

  <i class="el-icon-refresh" style="margin-right: 8px"></i>刷新</div>



 2.el-table表格数据

---------------



<el-table

      :data="tableData1"

      style="width: 98%"

      class="tableBox"

      stripe

      max-height="450"

    >

      <el-table-column label="序号" prop="index" width="55">

        <template slot-scope="scope">

          <span>{{ scope.$index + 1 }}</span>

        </template>

      </el-table-column>

      <el-table-column prop="sysName" label="设备名称" align="center">

      </el-table-column>

      <el-table-column label="操作" align="center" width="100">

        <template slot-scope="scope">

          <el-button

            type="text"

            :style="'padding:none'"

            @click="handleDetail1(scope.row)"

            >查看</el-button

          >

        </template>

      </el-table-column>



 表格绑定了tableData1,是根据getPerimeterData1()函数调接口获取到的列表数据



3\. search功能

------------



思路:遍历tableData1数组,对于满足条件的数组元素push到searchData数组,并最终把searchData赋值给tableData1.



// 前端实现查询功能

search1() {

  const key = this.formInline1.name; // 查询表单中的输入

  const vm = this;

  this.tableData1.forEach(function (item) {

    if (item.sysName.indexOf(key) > -1) {

      vm.searchData1.push(item);

    }

  });

  this.tableData1 = this.searchData1;

},



**问题1:**查询一次后,再次查询,tableData变成了两次查询的并集===>在每次查询前清空searchdata



**问题2:**先查询一个不存在的数据后, 再查询其他有数据的也不会显示了。===>因为查询一次之后,tableData的原始查询数组变小了===>需要有一份备份的tableData数据,即tableDataTemp,每次操作时使用tableDatatemp来进行



修改后的无误代码:



// 前端实现查询功能

search1() {

  this.flag1 = true;

  const key = this.formInline1.name; // 查询表单中的输入

  const vm = this;

  this.searchData1 = []; //清空查询数组-防止多次查询记录一直被push在最后

  console.log("查询前", this.tableDataTemp1);

  this.tableDataTemp1.forEach(function (item) {

    if (item.sysName.indexOf(key) > -1) {

      vm.searchData1.push(item);

    }

  });

  // this.resetData1 = this.tableData1;

  this.tableData1 = this.searchData1;

  console.log("查询后", this.tableData1);

},
最后

大厂面试问深度,小厂面试问广度,如果有同学想进大厂深造一定要有一个方向精通的惊艳到面试官,还要平时遇到问题后思考一下问题的本质,找方法解决是一个方面,看到问题本质是另一个方面。还有大家一定要有目标,我在很久之前就想着以后一定要去大厂,然后默默努力,每天看一些大佬们的文章,总是觉得只有再学深入一点才有机会,所以才有恒心一直学下去。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在el-dialog中实现新增el-table行的数据,需要进行以下步骤: 1. 在el-dialog中添加表单元素,用于输入新增行的数据。 2. 在表单中添加提交按钮,用于提交新增行的数据。 3. 在点击提交按钮时,将表单数据保存到一个对象中。 4. 将保存的对象添加到el-table的数据源中。 下面是一个简单的示例代码,演示如何在el-dialog中新增el-table行的数据: ``` <template> <div> <el-button type="primary" @click="showDialog">新增</el-button> <el-dialog :visible.sync="dialogVisible"> <el-form ref="form" :model="formData"> <el-form-item label="姓名"> <el-input v-model="formData.name"></el-input> </el-form-item> <el-form-item label="年龄"> <el-input v-model.number="formData.age"></el-input> </el-form-item> </el-form> <div slot="footer"> <el-button @click="dialogVisible = false">取消</el-button> <el-button type="primary" @click="addRow">提交</el-button> </div> </el-dialog> <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> <script> export default { data() { return { dialogVisible: false, formData: { name: '', age: 0 }, tableData: [ { name: '张三', age: 20 }, { name: '李四', age: 22 }, { name: '王五', age: 25 } ] }; }, methods: { showDialog() { this.dialogVisible = true; }, addRow() { this.tableData.push(this.formData); this.dialogVisible = false; this.$refs.form.resetFields(); } } }; </script> ``` 在上面的示例中,我们通过el-dialog实现了一个表单,用于输入新增行的数据。当点击提交按钮时,我们将表单数据保存到formData对象中,并将该对象添加到tableData数组中,从而实现了新增el-table行的数据。同时,我们还使用了$refs来重置表单数据,以便下一次新增行的操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值