• [element-ui] 表格点击出现编辑效果实现


    效果图

    单击之后出现编辑效果

    部分实现代码

    <template>
      <div @mousedown="editCtrl(currentEditRow, '')"
          <el-table :data="dataSet1"
          border
          size="mini"
          :summary-method="getSummaries"
          show-summary
          style=" 100%; margin-top: 20px"
               highlight-current-row
              >
                <el-table-column prop="sharePremRate" label="表格单击效果">
                  <template #default="scope">
                    <div @mousedown.stop>
                      <el-input
                        size="mini"
                        type="number"
                         @input="inputRegTest(scope, 'sharePremRate')"
                        @keydown.13.native="editCtrl(scope.row, '','dataSet1')"
                        v-model="scope.row.sharePremRate"
                        v-if="scope.row.isEdit=='sharePremRate'"
                      ></el-input>
                      <div
                        style=" 100%"
                        v-else
                        @mousedown="editCtrl(scope.row, 'sharePremRate','dataSet1')"
                      >
                        {{ scope.row.sharePremRate | persentSign }}%
                      </div>
                    </div>
                  </template>
                </el-table-column>
              </el-table>
      </div>
    </template>

    逻辑部分

    data(){
      return{
        dataSet1:[],
        dataSet2:[],
        dataSet3:[],
        dataSet4:[],
        dataSet5:[],
        dataSet6:[],
        dataSet7:[],
        currentEditRow: {},
      }
    },
    methods:{
    //单击编辑效果 editCtrl(row, filedNmae,data) {
        this.currentEditRow.isEdit=''
    this.currentEditRow = row; row.isEdit = filedNmae;
    //这里要强制刷新所有el-tabel组件 for(let i=1;i<=7;i++){ this[`dataSet1${i}`]=[...this[`dataSet1${i}`]] } },

    }
       <template>     
    <div v-loading='loading' class="app-container pb50" @mousedown="showEditTable(false)">
      <el-table-column label="表格单元" prop="alloSi" align="center">
           <template #default="{ row }">
                <div @mousedown.stop>
                    <el-input @blur='dsSumInsuredAfterChange(dsSumInsured)' v-if="row.ALLOSI_HIDDEN" size="mini" type='number' v-model.number="row.alloSi" />
                    <div v-else @mousedown="showEditTable(true,row,'ALLOSI_HIDDEN')"> {{ row.alloSi | comdifyFormat }}</div>
                </div>
           </template>
     </el-table-column>
     </div>
     </template>


            //单击触发编辑表格
            showEditTable(boolean, row, cell) {
                //判断什么状态可以编辑
                if (!this.isShow('create')) return
    
                if (boolean) {
                    //取消之前的编辑状态
                    if (this.enableEdit.cell) {
                        this.enableEdit.row[this.enableEdit.cell] = false
                    }
                    //激活编辑状态
                    this.enableEdit.row = row
                    this.enableEdit.cell = cell
                    row[cell] = true
                } else {
                    //取消之前的编辑状态
                    this.enableEdit.row[this.enableEdit.cell] = false
                }
                this.$forceUpdate()
            },
  • 相关阅读:
    shell的随机数
    centos7 安装install_mysql5.7网络教程安装_无报错.sh
    关于所有运动框架总结
    仅一年工作经验成功跳槽字节跳动,腾讯并拿到字节的offer,全靠这份面经!
    面试必看!花了三天整理出来的并发编程的锁及内存模型,看完你就明白了!
    新鲜出炉!花了三天整理的JVM复习知识点,面试突击必备!
    深度分析!面试99%被问到的多线程和并发篇,看完你就懂了
    去年去阿里面试,被问到ArrayList和LinkedList,我是这样回答的!
    深度分析:面试阿里,字节99%会被问到Java类加载机制和类加载器
    深度分析:Java并发编程之线程池技术,看完面试这个再也不慌了!
  • 原文地址:https://www.cnblogs.com/lv77/p/14802708.html
Copyright © 2020-2023  润新知