点击输入框弹出搜索框,输入关键字进行大量数据的搜索

1、点击弹出框的设置

 <el-form-item label="病例标签">
            <!-- <el-col :sm="22" :lg="20"> -->
            <el-popover placement="bottom" width="500" trigger="click">
              <div style="font-size: 14px">
                <el-input
                  style="width: 65%; margin-right: 1%"
                  size="mini"
                  v-model="cases"
                  class="search_name"
                  @input="changetag($event)"
                  placeholder="输入疾病标签关键字进行过滤搜索"
                ></el-input>
                <el-button type="primary" size="mini" @click="resetCasesTag"
                  >重置输入框</el-button
                >
              </div>
              <div
                class="titleCard"
                v-for="(item, index) in searchImport"
                :key="index"
              >
                <li
                  class="smallTItle"
                  v-for="(i, key) in item.title"
                  :key="key"
                  @click="casesCard(i, key)"
                  :class="{ activeColor: casesCode == i.code }"
                >
                  {{ i.name }}
                </li>
              </div>
              <template slot="reference">
                <!-- @input="changeMessage($event)" -->
                <el-input
                  :readonly="true"
                  @blur="changeMessage($event)"
                  v-model="casesDetail.tag"
                  placeholder="请选择疾病标签"
                  size="mini"
                  style="width: 80%; display: inline-block"
                  ref="caseblu"
                >
                  <i slot="prefix" class="el-input__icon el-icon-search"></i
                ></el-input>
                <el-button
                  style="margin-left: 1%; display: inline-block"
                  type="primary"
                  plain
                  size="mini"
                  @click="deleteCasesTag"
                  >删除</el-button
                >
              </template>
            </el-popover>
            <!-- </el-col> -->
          </el-form-item>

2、效果图

3、设置点击输入和删除等功能

//这里是点击下方的搜索条目的时候的事件。其实很多是项目中的逻辑代码,有一些对于其他项目的应用不是很需要,这里其实可以不用看
 drugCard(i) {
     
      this.casesDetail.drug_code = '';
      // 把旧值复值给一个变量
      this.oldDrugName = this.drugName;
      this.drugFlag = 1;
      // 把绑定的数值进行改变
      this.drugName = i.name;
      this.oldDrugCode = this.drugCode;
      this.drugCode = i.code;

      if (
        this.oldDrugName == this.drugName &&
        this.drugCode != this.oldDrugCode
      ) {
        this.getdrugData();
      }
      if (this.drugData) {
        for (const tag of this.drugData) {
          if (this.drugName == tag.name) {
            this.drugFlag = 0;
          }
        }
      }

      if (this.drugCode != this.oldDrugCode && this.drugFlag == 1) {
        this.drugData.push(i);
        if (!this.casesDetail.drug) {
          this.casesDetail.drug = this.drugName;
        } else {
          this.casesDetail.drug = this.casesDetail.drug + '、' + this.drugName;
        }
        // 点击存入的和返回的不一样
        for (const item of this.drugData) {
          if (!this.casesDetail.drug_code) {
            this.casesDetail.drug_code = item.code;
          } else {
            this.casesDetail.drug_code =
              this.casesDetail.drug_code + '、' + item.code;
          }
        }
      }
    },

4、当输入框输入的时候进行每隔一段时间发送请求获取内容

  watch: {
 
    cases() {
      if (this.cases == '') {
        this.casesCode = '';
        this.getSearchTitleCases();
        // this.countNum = 1;&& this.status != 1
      } else if (this.cases != '') {
        this.cur = '';
        // 实现input连续输入,只发一次请求
        clearTimeout(this.timeout);
        this.timeout = setTimeout(() => {
          this.getSearchTitleCases(this.casesCode || this.cases);
          this.casesCode = '';
          // this.countNum++;
        }, 300);
      }
    },
 
  },

5、一些输入框的事件,看着添加

// 强制更新测试文本信息框的值,焦点失去事件
    changeMessage() {
      this.$forceUpdate();
    },
 // 搜索疾病标签的输入框事件,输入事件
    changetag() {
      this.casesCode = '';
    },

6、删除的事件

 // 删除疾病标签的按钮
    deleteCasesTag() {
      if (this.tagData && this.addY) {
        this.data = this.tagData;
      }
      this.data.splice(this.data.length - 1, 1);
      // this.resetCases();
      this.$refs.caseblu.focus();
      this.$refs.caseblu.blur();
      this.casesDetail.tag_code = '';
      this.casesDetail.tag = '';
      for (const item of this.data) {
        if (!this.casesDetail.tag_code) {
          this.casesDetail.tag_code = item.code;
          this.casesDetail.tag = item.name;
        } else {
          this.casesDetail.tag_code =
            this.casesDetail.tag_code + '、' + item.code;
          this.casesDetail.tag = this.casesDetail.tag + '、' + item.name;
        }
      }
    },

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Vue3中使用Antd实现点输入一个Table表格的步骤如下: 1. 在组件中引入Table和Input组件 ```javascript <template> <div> <a-input-search v-model="search" placeholder="请输入关键字" @search="getTableData" @focus="showTable" /> <a-table v-if="show" :columns="columns" :dataSource="tableData" :loading="loading" /> </div> </template> <script> import { defineComponent } from 'vue' import { Table, Input } from 'ant-design-vue' export default defineComponent({ components: { 'a-table': Table, 'a-input-search': Input.Search }, data() { return { search: '', tableData: [], loading: false, show: false, // 是否显示Table组件 columns: [ { title: '姓名', dataIndex: 'name', key: 'name' }, { title: '年龄', dataIndex: 'age', key: 'age' }, { title: '地址', dataIndex: 'address', key: 'address' } ] } }, methods: { getTableData() { this.loading = true this.$axios.get('/api/data', { params: { search: this.search } }).then(res => { this.tableData = res.data this.loading = false }).catch(err => { console.error(err) this.loading = false }) }, showTable() { this.show = true } } }) </script> ``` 在这个例子中,我们使用了Input.Search来实现一个搜索框,当用户输入关键字并按下Enter键时,会触发search事件,调用getTableData方法来请求数据。当用户点输入框时,会触发focus事件,调用showTable方法来显示Table组件。我们使用一个show变量来控制Table组件的显示和隐藏。 2. 在组件中添加样式 ```css .a-table { position: absolute; top: 38px; left: 0; z-index: 999; width: 100%; } ``` 在这个例子中,我们使用了绝对定位将Table组件定位到输入框下方,并设置了z-index属性来保证Table组件始终处于最上层。我们还设置了Table组件的宽度为100%来适应父容器的宽度。 3. 在组件中添加点事件 ```javascript <template> <div> <a-input-search v-model="search" placeholder="请输入关键字" @search="getTableData" @click="showTable" /> <a-table v-if="show" :columns="columns" :dataSource="tableData" :loading="loading" /> </div> </template> <script> import { defineComponent } from 'vue' import { Table, Input } from 'ant-design-vue' export default defineComponent({ components: { 'a-table': Table, 'a-input-search': Input.Search }, data() { return { search: '', tableData: [], loading: false, show: false, // 是否显示Table组件 columns: [ { title: '姓名', dataIndex: 'name', key: 'name' }, { title: '年龄', dataIndex: 'age', key: 'age' }, { title: '地址', dataIndex: 'address', key: 'address' } ] } }, methods: { getTableData() { this.loading = true this.$axios.get('/api/data', { params: { search: this.search } }).then(res => { this.tableData = res.data this.loading = false }).catch(err => { console.error(err) this.loading = false }) }, showTable() { this.show = true document.addEventListener('click', this.hideTable) // 添加点事件 }, hideTable() { this.show = false document.removeEventListener('click', this.hideTable) // 移除点事件 } } }) </script> ``` 在这个例子中,我们在showTable方法中添加了一个click事件监听器,当用户点页面上任意位置时,会触发hideTable方法来隐藏Table组件。我们使用了addEventListener和removeEventListener方法来添加和移除点事件监听器,以避免内存泄漏。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值