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

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

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

最近項(xiàng)目需要實(shí)現(xiàn)可編輯的動(dòng)態(tài)多級表頭表格,看了兩天的文章,始終沒有找到我想要的效果,在了解了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)多級表頭table的文章就介紹到這了,更多相關(guān)vue render jsx 多級表頭table內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • VueJs組件prop驗(yàn)證簡單介紹

    VueJs組件prop驗(yàn)證簡單介紹

    今天看了vuejs的組件,看到了prop組件,主要作用是在傳入數(shù)據(jù)的時(shí)候?qū)魅氲闹底雠袛?,今天小編通過一個(gè)小例子給大家分享VueJs組件prop驗(yàn)證簡單理解,感興趣的朋友一起看看吧
    2017-09-09
  • vue實(shí)現(xiàn)登錄界面

    vue實(shí)現(xiàn)登錄界面

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)登錄界面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • vue使用計(jì)算屬性完成動(dòng)態(tài)滑竿條制作

    vue使用計(jì)算屬性完成動(dòng)態(tài)滑竿條制作

    這篇文章主要介紹了vue使用計(jì)算屬性完成動(dòng)態(tài)滑竿條制作,文章圍繞計(jì)vue算屬制作動(dòng)態(tài)滑竿條的相關(guān)代碼完成內(nèi)容,需要的朋友可以參考一下
    2021-12-12
  • 當(dāng)vue路由變化時(shí),改變導(dǎo)航欄的樣式方法

    當(dāng)vue路由變化時(shí),改變導(dǎo)航欄的樣式方法

    今天小編就為大家分享一篇當(dāng)vue路由變化時(shí),改變導(dǎo)航欄的樣式方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • 詳解vuelidate 對于vueJs2.0的驗(yàn)證解決方案

    詳解vuelidate 對于vueJs2.0的驗(yàn)證解決方案

    本篇文章主要介紹了vuelidate 對于vueJs2.0的驗(yàn)證解決方案,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2017-03-03
  • 親自動(dòng)手實(shí)現(xiàn)vue日歷控件

    親自動(dòng)手實(shí)現(xiàn)vue日歷控件

    這篇文章主要記錄了親自動(dòng)手實(shí)現(xiàn)vue日歷控件的詳細(xì)過程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-06-06
  • Vue中render函數(shù)調(diào)用時(shí)機(jī)與執(zhí)行細(xì)節(jié)源碼分析

    Vue中render函數(shù)調(diào)用時(shí)機(jī)與執(zhí)行細(xì)節(jié)源碼分析

    這篇文章主要為大家介紹了Vue中render函數(shù)調(diào)用時(shí)機(jī)與執(zhí)行細(xì)節(jié)源碼分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • vue3?keepalive源碼解析解決線上問題

    vue3?keepalive源碼解析解決線上問題

    這篇文章主要為大家講解了vue3?keepalive源碼解析解決線上問題,需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-07-07
  • 用vue設(shè)計(jì)一個(gè)數(shù)據(jù)采集器

    用vue設(shè)計(jì)一個(gè)數(shù)據(jù)采集器

    這篇文章主要介紹了如何用vue設(shè)計(jì)一個(gè)數(shù)據(jù)采集器,幫助大家更好的理解和學(xué)習(xí)使用vue框架,感興趣的朋友可以了解下
    2021-04-04
  • Vuejs開發(fā)環(huán)境搭建及熱更新【推薦】

    Vuejs開發(fā)環(huán)境搭建及熱更新【推薦】

    Vue.js是目前很火的一個(gè)前端框架,采用MVVM模式設(shè)計(jì),它是以數(shù)據(jù)驅(qū)動(dòng)和組件化的思想構(gòu)建的。本文重點(diǎn)給大家介紹Vuejs開發(fā)環(huán)境搭建及熱更新的相關(guān)知識(shí),需要的朋友參考下吧
    2018-09-09

最新評論

吴堡县| 武平县| 海安县| 泰安市| 浑源县| 南丰县| 易门县| 蒙山县| 尼勒克县| 江山市| 秦皇岛市| 塔河县| 峨眉山市| 吴忠市| 彝良县| 枞阳县| 博客| 新民市| 乌兰县| 射阳县| 葵青区| 陆丰市| 盱眙县| 上犹县| 库伦旗| 罗源县| 甘孜县| 镶黄旗| 互助| 江山市| 金乡县| 南宫市| 青田县| 斗六市| 长宁县| 南华县| 阿尔山市| 宜丰县| 宜君县| 阿瓦提县| 台东县|