最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue?ElementUI?table實(shí)現(xiàn)雙擊修改編輯某個(gè)內(nèi)容的方法

 更新時(shí)間:2024年09月29日 10:10:31   作者:Java小白中的菜鳥  
在實(shí)現(xiàn)表格單元格雙擊編輯功能時(shí),需使用@cell-dblclick事件來(lái)觸發(fā)雙擊操作,將單元格切換為input輸入框,通過(guò)ref引用和綁定失焦及回車事件來(lái)確認(rèn)編輯,同時(shí),需要處理編輯數(shù)據(jù)的更新和方法邏輯的完善

1、使用@cell-dblclick事件,當(dāng)雙擊時(shí)觸發(fā)事件

<el-table @cell-dblclick="handleCellDblClick"

2、單元格設(shè)置

主要重點(diǎn)為判斷雙擊時(shí)切換input框,然后綁定ref,設(shè)置失去焦點(diǎn)時(shí)觸發(fā)點(diǎn)方法,與按enter鍵觸發(fā)點(diǎn)方法

<el-table-column prop="name" label="姓名" width="180">
      <template slot-scope="scope">
        <span v-if="editableData !== scope.row">{{ scope.row.name }}</span>
        <el-input
          v-else
          :ref="'input-' + scope.$index"
          v-model="scope.row.name"
          @blur="handleInputBlur(scope.row)"
          @keyup.enter.native="handleInputEnter(scope.row)"
        ></el-input>
      </template>
    </el-table-column>

3、添加當(dāng)前編輯的數(shù)據(jù)

editableData: null, // 當(dāng)前編輯的數(shù)據(jù)項(xiàng)

4、為所有的方法賦予邏輯

// 雙擊時(shí)觸發(fā)
handleCellDblClick(row, column, cell, event) {
  if (column.property === 'customerBoxNum') {
    this.editableData = row; // 設(shè)置當(dāng)前編輯的數(shù)據(jù)項(xiàng)
    this.$nextTick(() => {
      const inputRef = 'input-' + this.boxList.indexOf(row);
      const inputElement = this.$refs[inputRef];
      if (inputElement) {
        inputElement.focus(); // 聚焦輸入框
      } else {
        console.error('Input element not found:', inputRef);
      }
    });
  }
},
handleInputBlur(row) {
  // 輸入框失去焦點(diǎn)時(shí)保存更改
  this.editableData = null; // 返回到靜態(tài)顯示狀態(tài)
},
handleInputEnter(row) {
  // 按下回車鍵時(shí)保存更改
  this.editableData = null; // 返回到靜態(tài)顯示狀態(tài)
},

5、打完收工

到此這篇關(guān)于VueElementUI table實(shí)現(xiàn)雙擊修改編輯某個(gè)內(nèi)容的方法的文章就介紹到這了,更多相關(guān)Vue ElementUI table雙擊修改內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

静海县| 射洪县| 金昌市| 太保市| 黄梅县| 石阡县| 镇坪县| 宁波市| 红原县| 湖北省| 武穴市| 普陀区| 河间市| 崇信县| 射洪县| 余干县| 开封市| 万宁市| 江西省| 泌阳县| 浮梁县| 英超| 民乐县| 塔城市| 剑河县| 乐业县| 庆元县| 彰武县| 大新县| 康保县| 蕉岭县| 朝阳区| 荣昌县| 鄂温| 宁都县| 阿坝| 长岛县| 东丽区| 天长市| 宜兰县| 周宁县|