• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
    問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
    當前位置: 首頁 - 科技 - 知識百科 - 正文

    對ElementUItable組件的源碼的詳細分析

    來源:懂視網 責編:小采 時間:2020-11-27 19:33:13
    文檔

    對ElementUItable組件的源碼的詳細分析

    對ElementUItable組件的源碼的詳細分析:本文章從如下圖所示的最基本的table入手,分析table組件源代碼。本人已經對table組件原來的源碼進行削減。本文只對重要的代碼片段進行講解,推薦下載代碼把項目運行起來,跟著文章的思路閱讀。思路<template> <p class="el-t
    推薦度:
    導讀對ElementUItable組件的源碼的詳細分析:本文章從如下圖所示的最基本的table入手,分析table組件源代碼。本人已經對table組件原來的源碼進行削減。本文只對重要的代碼片段進行講解,推薦下載代碼把項目運行起來,跟著文章的思路閱讀。思路<template> <p class="el-t
    本文章從如下圖所示的最基本的table入手,分析table組件源代碼。本人已經對table組件原來的源碼進行削減。本文只對重要的代碼片段進行講解,推薦下載代碼把項目運行起來,跟著文章的思路閱讀。

    思路

    <template>
     <p class="el-table">
     <!-- 隱藏列: slot里容納table-column -->
     <p class="hidden-columns" ref="hiddenColumns">
     <slot></slot>
     </p>
    
     <p class="el-table__header-wrapper"
     ref="headerWrapper">
     <table-header ref="tableHeader"
     :store="store">
     </table-header>
     </p>
    
     <p class="el-table__body-wrapper"
     ref="bodyWrapper">
     <table-body :context="context"
     :store="store"> 
     </table-body>
     </p>
     </p>
    </template>

    table、table-header、table-body、table-column之間通過table-store進行狀態管理。table-header、table-body對table-store數據進行監聽,每當table改變table-store數據時觸發table-header、table-body重新渲染。

    table-column為列數據column綁定相應的renderCell函數,供table-body渲染時使用。table-column這個組件自身不做任何渲染。所以會看到模板將其隱藏。還有就是table-header、table-body通過render函數進行渲染。

    初始化順序

    3596660871-5b57ca0dcc1eb_articlex.jpeg

    table

    1. 初始化store

      data() {
       const store = new TableStore(this);
       return {
       store,
       };
      }
    2. 將store共享給table-header、table-body

       <p class="el-table__header-wrapper"
       ref="headerWrapper">
       <table-header :store="store"></table-header>
       </p>
      
       <p class="el-table__body-wrapper"
       ref="bodyWrapper">
       <table-body :store="store"></table-body>
       </p>
    3. 將數據存儲到store,供table-body獲取data將其渲染

      watch: {
       data: {
       immediate: true,
       handler(value) {
       // 供 table-body computed.data 使用 
       this.store.commit('setData', value);
       // ......
       }
       },
      },
    4. 設置tableId

      created() {
       //.....
       this.tableId = `el-table_${tableIdSeed}`;
       //.....
       }
    5. 調用 updateColumns 觸發 table-header、table-body 二次render更新,標記mounted完成

      mounted() {
       // .....
       this.store.updateColumns();
       // .....
       this.$ready = true;
      }

    table-column

    1. 生成column,并為column綁定renderCell函數供table-body使用

      created(){
       // .........
       let column = getDefaultColumn(type, {
       id: this.columnId,
       columnKey: this.columnKey,
       label: this.label,
       property: this.prop || this.property,// 舊版element ui為property,現在的版本是prop
       type, // selection、index、expand
       renderCell: null,
       renderHeader: this.renderHeader, // 提供給table-column, table-column.js line 112
       width,
       formatter: this.formatter,
       context: this.context,
       index: this.index,
       });
       // .........
       
       // 提table-body使用, table-body.js line 69
       column.renderCell = function (createElement, data) {
       if (_self.$scopedSlots.default) {
       renderCell = () => _self.$scopedSlots.default(data);
       //<template slot-scope="{row}">
       //<span>{{row.frequentlyUsed | formatBoolean}}</span>
       //</template>
       }
       
       if (!renderCell) {// table-header不渲染index列的走這里,
       /*<p className="cell">王小虎</p>*/
       renderCell = DEFAULT_RENDER_CELL;
       }
       
       // <ElTableColumn
       // type="index"
       // width="50"/>
       return <p className="cell">{renderCell(createElement, data)}</p>;
       };
       
      }
    2. 給store.state._columns數組填充數據

      mounted() {
       // ...... 
       owner.store.commit('insertColumn', this.columnConfig, columnIndex, this.isSubColumn ? parent.columnConfig : null);
      }

    table-store

    table-store有兩個很重要的屬性_columns、data,_columns保存列的相關信息,data則保存開發者傳入的表格數據。還有兩個重要的函數insertColumn與updateColumns。

    1. insertColumn為_columns填充數據

      TableStore.prototype.mutations = {
       insertColumn(states, column, index, parent) {
       let array = states._columns;
       // ......
      
       if (typeof index !== 'undefined') {
       // 在index的位置插入column
       array.splice(index, 0, column);
       } else {
       array.push(column);
       }
      
       // .....
       },
      }
    2. updateColumns 對_columns進行過濾得到columns

      TableStore.prototype.updateColumns = function() {
       const states = this.states;
       const _columns = states._columns || [];
       
       const notFixedColumns = _columns.filter(column => !column.fixed);
       // .....
       const leafColumns = doFlattenColumns(notFixedColumns);
       // .....
       
       states.columns = [].concat(leafColumns);
       // ....
      }

    table-header、table-body

    table-header、table-body都擁有以下屬性

    props: {
     store: {
     required: true
     },
    }
    
    computed: {
     columns() {
     return this.store.states.columns;
     },
    },
    
    render(){
     // 渲染columns的數據
    }

    這兩個組件的工作原理是監聽columns數據變化以觸發render渲染。在table組件的mounted階段會調用 updateColumns 更新 columns,從而觸發 table-header、table-body 重新渲染。

    另外table-body還會監聽data變化,觸發render。例如當組件加載后發送請求,待請求響應賦值data,重新渲染table-body。

     computed: {
     data() {
     // table.vue watch.data 中 調用 setData 在store 中存儲 data
     return this.store.states.data;
     },
     },

    聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    對ElementUItable組件的源碼的詳細分析

    對ElementUItable組件的源碼的詳細分析:本文章從如下圖所示的最基本的table入手,分析table組件源代碼。本人已經對table組件原來的源碼進行削減。本文只對重要的代碼片段進行講解,推薦下載代碼把項目運行起來,跟著文章的思路閱讀。思路<template> <p class="el-t
    推薦度:
    標簽: 代碼 的代碼 分析
    • 熱門焦點

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 欧美日韩综合精品| 亚洲国产美女精品久久久久∴| 久久丝袜精品中文字幕| 国产精品久久久久jk制服| 欧美日韩国产成人高清视频,欧美日韩在线精品一 | 国产成人亚洲精品| 亚洲国产婷婷综合在线精品| 国产精品制服丝袜亚洲欧美| 久久久九九有精品国产| 精品免费人成视频app| 亚洲精品乱码久久久久久中文字幕| 国产欧美精品一区二区色综合| 精品视频一区二区三区在线观看| 国产在线精品一区二区在线观看| 一本久久a久久精品亚洲| 欧美国产成人精品一区二区三区 | 久久精品国产99国产精偷| 精品国产粉嫩内射白浆内射双马尾 | 久久91精品国产91久久麻豆| 久久ww精品w免费人成| 无码国内精品人妻少妇蜜桃视频| 日韩精品一区二区三区不卡| 久久se精品一区精品二区国产| 国产精品99久久久久久www| 日韩精品一区二区三区四区| 99国产精品久久| 2022国产精品福利在线观看| 久久精品a亚洲国产v高清不卡| 亚洲精品白浆高清久久久久久| 亚洲国产精品高清久久久| 伊人久久精品无码二区麻豆| 亚洲国产精品久久电影欧美| 亚洲精品夜夜夜妓女网| 一本色道久久综合亚洲精品| 亚洲AV永久无码精品成人| 日韩精品无码久久久久久| 四虎国产成人永久精品免费 | 成人精品视频成人影院| 国产精品内射婷婷一级二| 国产乱子伦精品无码专区| 九色精品视频在线观看|