el-table表格可编辑

需求:使用elementui的表格组件,实现某些列可以输入或者下拉选择修改行数据

html 复制代码
//tabClickLabel 只是作为区分是否可以修改列的条件
<el-table
                ref="table"
                :data="tableData"
                :header-cell-style="{ background: '#F5F7FA', height: '30px' }"
                style="width: 100%; margin: 0 auto"
                height="100%"
                align="center"
                stripe
                row-key="id"
                border
                :row-class-name="tableRowClassName"
                @cell-click="tabClick"
              >
                <el-table-column
                  v-for="(item, index) in viewColumns"
                  :key="index"
                  :fixed="item.fixed"
                  :prop="item.prop"
                  :align="item.align"
                  :label="item.label"
                  :min-width="item.width"
                  :show-overflow-tooltip="true"
                >
                  <template slot-scope="scope">
                    <!-- <span v-if="scope.row.index === tabClickIndex && tabLabel == item.label && tabClickLabel == '1'">
                      <el-input v-model="scope.row[item.prop]" v-focus size="small" @blur="inputBlur(scope.row)" />
                    </span> -->
                    <span v-if="scope.row.index === tabClickIndex && tabLabel == item.label && tabClickLabel == '2'">
                      <el-select v-model="scope.row[item.prop]" v-focus size="small" style="width: 100%" @change="handleChange($event, scope.row,item.prop)">
                        <el-option v-for="and in dt_stylishly" :key="and.id" :label="and.text" :value="and.id" />
                      </el-select>
                    </span>
                    <span v-else-if="scope.row.index === tabClickIndex && tabLabel == item.label && tabClickLabel == '4'">
                      <el-select v-model="scope.row[item.prop]" v-focus size="small" style="width: 100%" multiple @visible-change="(v) => handleBulr(v,scope.row)">
                        <el-option v-for="and in dt_stylishlyFour" :key="and.id" :label="and.text" :value="and.id" />
                      </el-select>
                    </span>
                    <span v-else v-html="intFormatter(scope.row[item.prop], item.prop)" />
                  </template>
                </el-table-column>
              </el-table>

tabClick方法里面处理修改数据

javascript 复制代码
    tabClick(row, column, cell, event) {
      if (this.viewColumns.some((ele) => ele.label == column.label)) {
        this.tabClickIndex = row.index
      }
      if (column.label == '部品表编号') {
        this.tabClickLabel = '0'
      } else if (column.label == '初始式样') {
        this.tabClickLabel = '2'
      } else if (column.label == '初始区域') {
         //里面的逻辑具体按照 后端需要的数据进行获取
        this.tabClickLabel = '4'
        // 这个地方给的是中文
        if (row.divType) {
          if (!Array.isArray(row.divType)) {
            let str = []
            if (row.divType.includes('/')) {
              str = row.divType.split('/')
            } else {
              str = [row.divType]
            }
            const texts = str.map(text => {
              const item = this.dt_stylishlyFour.find(obj => obj.text === text) // 查找符合条件的对象
              return item ? item.id : '' // 如果找到对象,返回其 text 字段;否则返回空字符串
            })
            row.divType = texts
          }
        }
      } else {
        this.tabClickLabel = '1'
      }
      this.tabLabel = column.label
    },
相关推荐
counterxing3 小时前
我整理了一个免费开发资源目录,还做成了 CLI 和 MCP
前端·agent·ai编程
子兮曰9 小时前
Bun v1.3.14 深度解析:Image API、HTTP/3、全局虚拟存储与五十项变革
前端·后端·bun
kyriewen10 小时前
今天,百年巨头一次砍了9200人,而一个离职科学家的实话让全网睡不着觉
前端·openai·ai编程
问心无愧051311 小时前
ctf show web 入门42
android·前端·android studio
kyriewen11 小时前
老板逼我上AI,我偷偷在浏览器里跑LLaMA,省下20万API费
前端·react.js·llm
Beginner x_u11 小时前
前端八股整理(手写 02)|数组转树、数组扁平化、随机打乱一个数组
前端·数组·数组转树·数组扁平化
KaMeidebaby11 小时前
卡梅德生物技术快报|禽类成纤维细胞 FISH 实验:鸟类性别染色体基因定位技术实现与数据验证
前端·数据库·其他·百度·新浪微博
天若有情67311 小时前
前端高阶性能优化:跳出传统懒加载与预加载,基于用户行为做轻量预判加载
前端·性能优化
小小小小宇11 小时前
前端转后端:SQL 是什么
前端
张元清12 小时前
React Observer Hooks:7 种监听 DOM 而不写样板代码的方式
前端·javascript·面试