vue+element-ui实现表格编辑

 动态生成表格模板

  <el-table max-height="400"
              :data="tableData"
              stripe
              style="width:100%;"
              class="tb-edit"
              @row-dblclick="row_dblclick">
      <el-table-column :width="dataArrHeader.length >=4?'200px':''"
                       :prop="el.prop"
                       :label="el.label"
                       align="left"
                       v-for="(el, ind) in dataArrHeader"
                       :key="ind"
                       show-overflow-tooltip>
        <template slot-scope="scope">
          <el-input size="mini"
                    v-model="scope.row[el.prop]"
                    placeholder="请输入内容"
                    v-if="scope.row.showEdit"></el-input>
          <span v-else>{{ scope.row[el.prop] }}</span>
        </template>
      </el-table-column>
      <el-table-column label=""
                       width="40">
        <template slot-scope="scope">
          <span class="el-icon-circle-close"
                @click="deleteData(scope.$index,scope.row)"
                v-if="scope.row.showEdit"></span>
        </template>
      </el-table-column>
  </el-table>
 getData () {
      // 获取预览数据
      let query = {
        dbName: this.authDataObj.dbName,
        dbUser: this.authDataObj.dbUser,
        tabCnName: this.authDataObj.tabCnName,
        tabName: this.authDataObj.tabName,
        type: this.authDataObj.type,
        id: this.authDataObj.id,
        createDate: this.authDataObj.createDate
      }
      this.$http.post(this.apiurl, query).then(res => {
        this.dataArrHeader = []
        const objT = res.object.data.fieldMeta[0] || {}
        // synchronize
        Object.keys(objT).forEach((it) => {
          if (objT[it]) {
            let objTs = {}
            objTs.prop = it
            objTs.label = objT[it]
            this.dataArrHeader.push(objTs)
          }
        })
       
        res.object.data.fieldMeta.map(v => {
          v.showEdit = false
        })
        this.tableData = res.object.data.fieldMeta
        this.tableData[this.tableData.length - 1].showEdit = true
        console.log(this.tableData)
      }).catch(err => {
        console.log(err)
      }).finally(() => {
        this.listLoading = false
      })
    },
 row_dblclick (row, event) {
      this.tableData.map(v => {
        if (row === v) {
          v.showEdit = true
        } else {
          v.showEdit = false
        }
      })
    },

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值