table表格的某一行数据如何回填

目的:table表格的某一行数据的输入框按钮触发对话框,对话框选择的数据再回填到table表格的这一行中。

1.插槽中传递本行的index: v-slot="{ row, $index }"

2.点击事件或者change事件传递index: @click="val => tpmClicked($index)"

  1. 记录这个index值:

    const rowIndexTPM = ref<number>();
    const tpmClicked = async index => {
    rowIndexTPM.value = index;
    dialogTPMVisible.value = true;
    };

  2. 对话框选择后触发事件,使用这个index值:

    const TPMchangeInfo = (jobNumber: string) => {
    requireList.value[rowIndexTPM.value].JobNumber = jobNumber;
    dialogTPMVisible.value = false;
    changeInfo(requireList.value[rowIndexTPM.value]);
    };

代码数据:

复制代码
1. 记录index
    <el-table-column label="工号" prop="JobNumber">
      <template v-slot="{ row, $index }">
        <span v-if="editStatus">
          <el-input
            type="text"
            v-model="row.JobNumber"
            placeholder="请输入:"
            @change="val => changeInfo(row)"
          >
            <template #suffix v-if="row.WorkerRole == 'TPM'">
              <el-button
                type="primary"
                @click="val => tpmClicked($index)"
                v-if="row.WorkerRole == 'TPM'"
                link
              >
                <el-icon>
                  <Connection />
                </el-icon>
              </el-button>
            </template>
          </el-input>
        </span>
        <span v-else>{{ row.JobNumber }}</span>
      </template>
    </el-table-column>



-->  触发的事件:
const rowIndexTPM = ref<number>();
const tpmClicked = async index => {
  rowIndexTPM.value = index;
  dialogTPMVisible.value = true;
};



2.对话框:
<el-dialog v-model="dialogTPMVisible" title="请选择TPM工号" width="20%">
    <el-tree-select
      v-model="Value"
      :data="TPMListInfo"
      filterable
      placeholder="请输入:"
      @change="val => TPMchangeInfo(val)"
    />
  </el-dialog>

--> 事件触发:
const TPMchangeInfo = (jobNumber: string) => {
  requireList.value[rowIndexTPM.value].JobNumber = jobNumber;
  dialogTPMVisible.value = false;
  changeInfo(requireList.value[rowIndexTPM.value]);
};


--> 数据源:
const TPMListInfo = computed(() => {
  console.log("data houduan: ", props.TPMGroups);
  return props.TPMGroups.map(item => {
    return {
      value: "",
      label: item.DepName,
      children: item.TPMList.map(t => {
        return {
          value: t.JobNumber,
          label: t.WorkerName + "/" + t.JobNumber,
          children: []
        };
      })
    };
  });
});
相关推荐
明远湖之鱼1 分钟前
巧用 Puppeteer + Cheerio:批量生成高质量 Emoji 图片
前端·爬虫·node.js
落笔忆梦3 分钟前
利用浏览器空闲时间优化资源加载与渲染
前端·javascript
艾小码4 分钟前
还在用Vue 2硬撑?升级Vue 3的避坑指南来了!
前端·javascript·vue.js
是晓晓吖4 分钟前
page.waitForResponse 执行环境:页面还是 Node.js?
前端·puppeteer
三十_5 分钟前
【Docker】学习 Docker 的过程中,我是这样把镜像越做越小的
前端·后端·docker
Mintopia6 分钟前
🌐 交互式 AIGC:Web 端实时反馈生成的技术架构设计
前端·javascript·aigc
蓝天星空7 分钟前
ES6-Promise用法
前端·javascript·es6
诗书画唱10 分钟前
解决HTML/JS开发中的常见问题与实用资源
前端·javascript·html
Mintopia12 分钟前
🚀 Next.js 自建部署全家桶:Docker + PM2 + Nginx
前端·javascript·全栈
鹏多多14 分钟前
详解vue渲染函数render的使用
前端·javascript·vue.js