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

element-ui直接在表格中點(diǎn)擊單元格編輯

 更新時間:2021年12月07日 09:59:19   作者:阿雷前進(jìn)中...  
最近通過在網(wǎng)上查找資料,自己整合研究了一個可以直接在表格中操作數(shù)據(jù)的基于element-ui的前端模板??梢宰屧龈臄?shù)據(jù)的操作顯得方便一點(diǎn),感興趣的可以了解一下

最近由于公司開始使用elementUI,開發(fā)的過程中需要用到對表格的單元格進(jìn)行編輯,下面是我自己實(shí)現(xiàn)表格可編輯的方式,感興趣的可以了解一下

實(shí)現(xiàn)效果

在這里插入圖片描述

編輯之后對應(yīng)表格數(shù)據(jù)該字段值也就發(fā)生了變化,控制臺輸出所有數(shù)據(jù)即可查看變化

實(shí)現(xiàn)代碼

1、自定義編輯組件

<template>
  <div class="editCell">
    <div class="canEdit" v-if="CanEdit" @click="beginEdit">
      <label v-show="!editStatus">
        <span v-if="this.value!== null && this.value !== undefined && this.value !== ''">{{ value }}{{this.suffix}}</span>
        <span v-else style="padding-left: 100%;padding-top: 100%;"/>
      </label>
      <label v-show="editStatus">
        <input
          type="text"
          class="inputClass"
          ref="input"
          v-on:keyup.13="loseFocus"
          :value="value"
          @blur="loseFocus"
        />
      </label>
    </div>

    <label class="cannotEdit" v-else>
      <span>{{ value }}{{ suffix }}</span>
    </label>
  </div>
</template>

<script>
export default {
  name: "EditCell",
  props: {
    /**
     * 綁定值
     */
    value: {
      required: true
    },
    /**
     * 是否可編輯
     */
    CanEdit: {
      type: Boolean,
      default: true
    },
    /**
     * 格式化函數(shù)
     */
    formatData: {
      type: Function,
      default: value => {
        return value;
      }
    },
    /**
     * 編輯后事件
     */
    afterEdit: {
      type: Function,
      default: () => {}
    },
    /**
     * 是否初始格式化
     */
    initFormat: {
      type: Boolean,
      default: false
    },
    suffix: {
      default: ""
    }
  },
  data() {
    return {
      editStatus: false,
      showData: "",
      defaultData: "",
      timeout: null
    };
  },
  methods: {
    /**
     * 單擊開始編輯
     */
    beginEdit() {
      this.editStatus = true;
      setTimeout(() => {
        this.$refs.input.focus();
      }, 1);
    },

    /**
     * @param {event} event
     * 丟失焦點(diǎn)關(guān)閉編輯狀態(tài),并保存數(shù)據(jù)
     */
    loseFocus(event) {
      let value = this.formatData(event.target.value);
      this.editData(value);
      this.closeEditStatus(value);
      this.afterEdit(value);
    },

    /**
     * 發(fā)布input事件修改數(shù)據(jù)
     * @param value
     */
    editData(value) {
      this.$emit("input", value);
    },

    /**
     * 關(guān)閉編輯狀態(tài)
     * @param value
     */
    closeEditStatus(value) {
      this.editStatus = false;
    },
    /**
     * 初始格式化數(shù)據(jù)
     */
    initData() {
      let newValue = this.formatData(this.value);
      this.$emit("input", newValue);
    }
  },
  mounted() {
    if (this.initFormat) {
      this.initData();
    }
  },
  watch: {
    'value': function(newVal){
      this.$emit("input", this.formatData(newVal));
    }
  }
};
</script>

<style scoped>
.editCell {
  height: 100%;
  width: 100%;
}
.inputClass {
  height: 30px;
  width: 100%;
  background-color: #fff;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  color: #606266;
  display: inline-block;
  font-size: inherit;
  line-height: 30px;
  outline: 0;
  padding: 0 15px;
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  overflow: visible;
  touch-action: manipulation;
  margin: 0;
}
</style>

頁面調(diào)用

import EditCell from "@/components/EditCell/EditCell";
components: { EditCell},

 <el-table-column
    v-for="item in tableColumn"
      :prop="item.dataIndex"
      :label="item.title"
      :width="item.width"
      :align="item.align"
      :key="item.id"
      :fixed="item.fixed"
  >
  	  //此處調(diào)用自定義組件(dataIndex 為表頭數(shù)據(jù)中字段,相當(dāng)于 展示表頭 老師對應(yīng)的 teacher名稱)
      <template slot-scope="scope">
          <span v-if="item.dataIndex !== 'batchInvest' && item.dataIndex !== 'remark'">{{scope.row[item.dataIndex]}}</span>
          // 若需要格式化數(shù)據(jù) 可設(shè)置 :format-data="formatFun" formatFun此方法在當(dāng)前頁methods中定義即可
          <edit-cell v-else v-model="scope.row[item.dataIndex]" :can-edit="true"/>
      </template>
      <el-table-column
          v-for="item2 in item.children"
          :prop="item2.dataIndex"
          :label="item2.title"
          :width="item2.width"
          :align="item2.align"
          :key="item2.id"
          :fixed="item2.fixed"
      >
      </el-table-column>
  </el-table-column>

到此這篇關(guān)于element-ui直接在表格中點(diǎn)擊單元格編輯的文章就介紹到這了,更多相關(guān)element 單元格編輯內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue CL3 配置路徑別名詳解

    Vue CL3 配置路徑別名詳解

    這篇文章主要介紹了Vue CL3 配置路徑別名詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • 解決Vue開發(fā)中對話框被遮罩層擋住的問題

    解決Vue開發(fā)中對話框被遮罩層擋住的問題

    在Vue的開發(fā)中,一旦我們用到對話框,經(jīng)常出現(xiàn)的問題是對話框被遮罩層擋住,怎么來解決這個問題呢?下面小編給大家?guī)砹薞ue開發(fā)中對話框被遮罩層擋住的問題及解決方法,一起看看吧
    2018-11-11
  • elementUI中的$confirm調(diào)換兩個按鈕位置的實(shí)例代碼

    elementUI中的$confirm調(diào)換兩個按鈕位置的實(shí)例代碼

    這篇文章主要介紹了elementUI中的$confirm調(diào)換兩個按鈕位置的實(shí)例代碼,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
    2024-03-03
  • 一文帶你搞懂Vue中i18n的使用方法

    一文帶你搞懂Vue中i18n的使用方法

    i18n是"國際化"的簡稱,它的主要目的是讓應(yīng)用程序能夠適應(yīng)不同的語言和地區(qū)的需求,下面就跟隨小編一起來看看Vue中i18n的具體使用方法吧
    2025-01-01
  • 基于 flexible 的 Vue 組件:Toast -- 顯示框效果

    基于 flexible 的 Vue 組件:Toast -- 顯示框效果

    這篇文章主要介紹了基于 flexible 的 Vue 組件:Toast -- 顯示框效果,需要的朋友可以參考下
    2017-12-12
  • 詳解Vue3頁面如何自適應(yīng)表格滾動高度

    詳解Vue3頁面如何自適應(yīng)表格滾動高度

    這篇文章主要為大家詳細(xì)介紹了Vue3頁面如何自適應(yīng)表格滾動高度,文中的示例代碼講解詳細(xì),具有一定的借鑒價值,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-02-02
  • Vue3+TS實(shí)現(xiàn)語音播放組件的示例代碼

    Vue3+TS實(shí)現(xiàn)語音播放組件的示例代碼

    這篇文章主要介紹了如何利用Vue+TS實(shí)現(xiàn)一個簡易的語音播放組件,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)Vue有一定的幫助,需要的可以參考一下
    2022-03-03
  • vue中的data,computed,methods,created,mounted用法及說明

    vue中的data,computed,methods,created,mounted用法及說明

    這篇文章主要介紹了vue中的data,computed,methods,created,mounted用法及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • Vue3實(shí)現(xiàn)動態(tài)面包屑的代碼示例

    Vue3實(shí)現(xiàn)動態(tài)面包屑的代碼示例

    這篇文章主要給大家介紹一下Vue3動態(tài)面包屑是如何實(shí)現(xiàn)的,實(shí)現(xiàn)思路又是什么,以及發(fā)給大家介紹一下面包屑的功能,文章通過代碼示例介紹的非常詳細(xì),需要的朋友可以參考下
    2023-07-07
  • vue3 axios安裝及使用示例詳解

    vue3 axios安裝及使用示例詳解

    這篇文章主要介紹了vue3 axios安裝及使用示例代碼,本文通過示例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
    2024-04-04

最新評論

马公市| 台东县| 贵州省| 安宁市| 鄯善县| 蓝山县| 望谟县| 吴堡县| 泸州市| 平潭县| 仙居县| 旺苍县| 永兴县| 宜良县| 普安县| 吉林省| 区。| 冕宁县| 阿图什市| 中山市| 特克斯县| 府谷县| 鲁山县| 多伦县| 思茅市| 贵州省| 确山县| 平遥县| 民丰县| 高密市| 云霄县| 迁西县| 旬阳县| 兴仁县| 丰县| 华蓥市| 景洪市| 牡丹江市| 临朐县| 伊通| 内丘县|