欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue+render+jsx實(shí)現(xiàn)可編輯動(dòng)態(tài)多級(jí)表頭table的實(shí)例代碼

 更新時(shí)間:2020年04月01日 09:43:11   作者:qq_42901018  
這篇文章主要介紹了vue+render+jsx實(shí)現(xiàn)可編輯動(dòng)態(tài)多級(jí)表頭table的實(shí)例代碼,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的工作或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

最近項(xiàng)目需要實(shí)現(xiàn)可編輯的動(dòng)態(tài)多級(jí)表頭表格,看了兩天的文章,始終沒有找到我想要的效果,在了解了render+jsx的基礎(chǔ)用法后,自己基于element-ui封裝了一個(gè),數(shù)據(jù)格式參考element-ui table的數(shù)據(jù)。實(shí)現(xiàn)如下:

1.scoresTable

<script>
  import scoresColumn from "./scoresColumn";
  export default {
    components: {
      scoresColumn
    },
    render: function(h) {
      return <div className="table-control">
        <el-table ref="table"
             size="small"
             {...{attrs: {data:this.tableData}}}
             border
        >
          {
            this.tableTitles.map(title => {
              return <scoresColumn on-dataChange={this.dataChange} {...{attrs: {column:title,unitScores: this.unitScores}}}></scoresColumn>
            })
          }

        </el-table>
      </div>;
    },
    props: {
      tableTitles: {
        type: Array,
        default: () => []
      },
      tableData: {
        type: Array,
        default: () => []
      },
      unitScores: {
        type: Object,
        default: () => {}
      }
    },
    methods: {
      dataChange(id) {
        this.$emit('dataChange', id);
      }
    },
  }
</script>
<style>
 .el-table th, .el-table td {
  text-align: center;
 }
</style>

2.scoresColumn

<script>
  export default {
    data() {
     return {
       style: {
         'min-width': "70",
         'resizable': true,
         'show-overflow-tooltip': true
       },
     }
    },
    props: {
     column: {
       type: Object
     },
     unitScores: {
       type: Object,
       default: () => {}
     }
    },
    name: "scoresColumn",
    render: function (h) {
      let scopedSlots = {
        default: (scope) => {
          let col = scope.column.property;
          let value = scope.row[col];
          return <div id={col+scope.$index} >
            <p onClick={this.clickHandle}>{value}</p>
          </div>;
        }
      };
      if (this.column.children === undefined)
        if (this.column.label == '序號(hào)' || this.column.label == '姓名') {
          return <el-table-column fixed
            {...{style: this.style, scopedSlots: {
                default: (scope) => {
                  let value = scope.row[scope.column.property];
                  return <p>{value}</p>;
                }
              }}}
            prop={this.column.prop} label={this.column.label}>
          </el-table-column>
        }else {
          return <el-table-column
             {...{style: this.style, scopedSlots: {
                default: (scope) => {
                  let value = scope.row[scope.column.property];
                  if (/\((?=\d)|(^總計(jì)$)/g.test(this.column.label)) {
                    let col = scope.column.property;
                    return <div id={col+scope.$index} >
                      <p onClick={this.clickHandle}>{value}</p>
                     </div>;
                  }else return <p>{value}</p>;
                }
               }}}
             prop={this.column.prop} label={this.column.label}>
          </el-table-column>
        }
      let buildTitles = (childList) => {
        let children = [];
        childList.map(child => {
          if (child.children != undefined && child.children.length > 0) {
            children.push(<el-table-column {...{style: this.style}} label={child.label}>
              {buildTitles(child.children)}
            </el-table-column>)
          } else {
            children.push(
              <el-table-column {...{style: this.style, scopedSlots: scopedSlots}}
                       label={child.label} prop={child.prop}>
              </el-table-column>)
          }
        });
        return children;
      };
      return <el-table-column
        {...{style: this.style}}
        label={this.column.label}
        prop={this.column.prop}>
        {buildTitles(this.column.children)}
      </el-table-column>;
    },
    methods: {
      blurHandler(e) {
        let parent = e.target.parentNode;
        let child = parent.firstElementChild;
        let p = document.createElement('p');
        let value = child.value.match(/^\d*(\.{1}\d+)?/)[0];
        if (value == '' || value == null) {
          value = 0;
        }
        p.innerHTML = value;
        p.addEventListener('click', this.clickHandle, false);
        child.replaceWith(p);
        this.$emit('dataChange', parent.id);
      },
      clickHandle(e) {
        let parent = e.target.parentNode;
        let child = parent.firstElementChild;
        let input = document.createElement('input');
        input.style.lineHeight = '23px';
        input.style.textAlign = 'center';
        input.style.fontSize = '12px';
        input.style.height = '23px'
        input.style.width = '100%';
        input.value = child.innerHTML;
        input.addEventListener('blur', this.blurHandler, true);
        input.addEventListener('keyup', this.keyUpHandler, false);
        child.replaceWith(input);
        input.focus();
      },
      keyUpHandler(e) {
        let input = e.target;
        let parent = input.parentNode;
        let property = parent.id.replace(/\d/g, '');
        let value = input.value.replace(/[^\d\.]/g,'');
        if (Math.min(this.unitScores[property],value) != value) {
          value = this.unitScores[property];
        }
        input.value = value;
      }
    }
  }
</script>
<style scoped>
</style>

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

在這里插入圖片描述
在這里插入圖片描述

總結(jié)

到此這篇關(guān)于vue+render+jsx實(shí)現(xiàn)可編輯動(dòng)態(tài)多級(jí)表頭table的文章就介紹到這了,更多相關(guān)vue render jsx 多級(jí)表頭table內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue中狀態(tài)管理器Pinia的用法詳解

    vue中狀態(tài)管理器Pinia的用法詳解

    Pinia?是?Vue.js?的輕量級(jí)狀態(tài)管理庫(kù),最近很受歡迎,它使用?Vue?3?中的新反應(yīng)系統(tǒng)來(lái)構(gòu)建一個(gè)直觀且完全類型化的狀態(tài)管理庫(kù),下面就跟隨小編一起來(lái)學(xué)習(xí)一下它的具體使用吧
    2023-10-10
  • Vuejs中使用markdown服務(wù)器端渲染的示例

    Vuejs中使用markdown服務(wù)器端渲染的示例

    這篇文章主要介紹了Vuejs 中使用 markdown的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-11-11
  • vue使用recorder.js實(shí)現(xiàn)錄音功能

    vue使用recorder.js實(shí)現(xiàn)錄音功能

    這篇文章主要為大家詳細(xì)介紹了vue使用recorder.js實(shí)現(xiàn)錄音功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • 基于vue中的scoped坑點(diǎn)解說(shuō)

    基于vue中的scoped坑點(diǎn)解說(shuō)

    這篇文章主要介紹了基于vue中的scoped坑點(diǎn)解說(shuō),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-09-09
  • vux uploader 圖片上傳組件的安裝使用方法

    vux uploader 圖片上傳組件的安裝使用方法

    這篇文章主要介紹了vux-uploader 圖片上傳組件的安裝及使用方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-05-05
  • element-ui循環(huán)顯示radio控件信息的方法

    element-ui循環(huán)顯示radio控件信息的方法

    今天小編就為大家分享一篇element-ui循環(huán)顯示radio控件信息的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-08-08
  • Element?el-tag標(biāo)簽圖文實(shí)例詳解

    Element?el-tag標(biāo)簽圖文實(shí)例詳解

    現(xiàn)在好多應(yīng)用場(chǎng)景里會(huì)有一些需要給文章打標(biāo)簽等類似的操作,下面這篇文章主要給大家介紹了關(guān)于Element?el-tag標(biāo)簽的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-04-04
  • 關(guān)于Vue.js一些問題和思考學(xué)習(xí)筆記(2)

    關(guān)于Vue.js一些問題和思考學(xué)習(xí)筆記(2)

    這篇文章主要為大家分享了關(guān)于Vue.js一些問題和思考的學(xué)習(xí)筆記,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • Vue 使用超圖SuperMap的實(shí)踐

    Vue 使用超圖SuperMap的實(shí)踐

    作為一名剛?cè)腴T計(jì)算機(jī)語(yǔ)言的人來(lái)說(shuō),要想快速完成測(cè)試開發(fā)地圖項(xiàng)目,肯定要接用到SuperMap,本文主要介紹了Vue 使用超圖SuperMap的實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • Vue前端開發(fā)規(guī)范整理(推薦)

    Vue前端開發(fā)規(guī)范整理(推薦)

    本文是基于vue官方風(fēng)格指南整理的關(guān)于Vue前端開發(fā)規(guī)范(推薦),非常不錯(cuò),具有參考借鑒借鑒價(jià)值,需要的朋友可以參考下
    2018-04-04

最新評(píng)論