根据输入框输入的内容筛选表格数据的两种方法

该文章介绍了如何在Vue.js应用中通过输入框内容筛选表格数据,包括添加搜索按钮触发搜索功能,以及提供重置按钮清除搜索条件。方法涉及v-model绑定,@change事件,以及watch监听器来实时更新数据。
摘要由CSDN通过智能技术生成

根据输入框输入的内容筛选表格数据的两种方法

加搜索按钮

<div class="search">
        <div class="searchLabel">资源名称:</div>
        <div class="searchInput">
          <el-input
            v-model.trim="name"
            @change="changeEvent"
            placeholder="请输入型号"
          ></el-input>
        </div>
        <el-button type="primary" @click="addList">新建</el-button>
        <el-button type="primary" @click="searchFn">搜索</el-button>
        <el-button type="primary" @click="resetFn">重置</el-button>
      </div>
      name: "",
      input:"",
  mounted() {
    this.getData();
  },
methods: {
    // 获取用户信息
    async getData() {
      const params = {
        currentPage: this.page.currentPage,
        size: this.page.pageSize,
        model:this.input,
      };
      const res = await getD(params);
      console.log(res, "res");
      if (res.data.code == 200) {
        this.tableData = res.data.data.records;
        this.page.totalResult = res.data.data.total;
      }
    },
    changeEvent(val){
      this.input = val;
      console.log(this.input,'this.input');
    },
    // 搜索
    searchFn(){
      this.getData();
    },
    // 重置
    resetFn() {
      this.name = "";
      this.getData();
    },
    }

无搜索按钮

 watch:{
    name(val){
    this.input = val
      this.getData(this.input);
    }
  },
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值