如何用VUE在table表格中使用input输入框

一 单元格中包含文字+input

<template>
  <div>
    <div class="title">销售行为-- 标签设置</div>
    <el-table :data="userList" border :header-cell-style="{ background: '#f5f5f5' }">
      <el-table-column prop="caozuo" label="销售行为" width="180" />
      <el-table-column prop="userName" label="时间限定" width="400px">
        <template #default="scope">
          超过
          <el-input v-model="scope.row.userName" style="width: 60px; margin: 0px 15px" clearable />
          {{ scope.row.desc }}
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script lang="ts" setup>
import { ref } from "vue"
//原数据集
const userList = ref([
  {
    caozuo: "首次跟进",
    userName: 123,
    desc: "小时未跟进"
  },
  {
    caozuo: "成交",
    userName: 456,
    desc: "天未成交"
  }
])
</script>

<style scoped>
.title {
  border-left: 3px solid red;
  margin-bottom: 20px;
  padding-left: 20px;
}
</style>

配置表头颜色

:header-cell-style="{ background: '#f5f5f5' }"

二 只有input

<template>
  <div>
    <fieldset>
      <legend>如何用VUE在table表格中使用input输入框</legend>
      <el-table :data="userList" style="width: 100%">
        <el-table-column prop="userId" label="编号" width="180" />
        <el-table-column prop="userName" label="姓名" width="180">
          <template slot-scope="scope">
            <el-input
              placeholder="请输入姓名"
              v-model="scope.row.userName"
              clearable
            />
          </template>
        </el-table-column>
        <el-table-column prop="phone" label="手机号" width="180" />
        <el-table-column prop="sex" label="性别" width="180" />
      </el-table>
    </fieldset>
  </div>
</template>
<script>
export default {
  created: function () {},
  data() {
    return {
      //原数据集
      userList: [
        {
          userId: 1,
          userName: "",
          phone: 123,
          sex: "男",
        },
        {
          userId: 2,
          userName: "",
          phone: 456,
          sex: "女",
        },
        {
          userId: 3,
          userName: "",
          phone: 789,
          sex: "男",
        },
      ],
    };
  },
  methods: {},
};
</script>

<style scoped>
fieldset {
  /* 表单页面居中,宽度50% ,legend颜色设置,legend圆角*/
  border: 2px solid #dcdfe6;
  text-align: left;
  border-radius: 8px;
  margin: 0 auto;
  width: 50%;
}
</style>

如何用VUE在table表格中使用input输入框_table里放input-CSDN博客

VUE element-ui之table表格中嵌套输入框,且输入框失焦自动勾选当前行_vue element-ui之table表格中嵌套输入框,且输入框失焦不要自动勾选当前行-CSDN博客

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue3使用Antd实现点击输入框弹出一个Table表格的步骤如下: 1. 在组件引入TableInput组件 ```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、付费专栏及课程。

余额充值