<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答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
        主站蜘蛛池模板: 久久午夜夜伦鲁鲁片免费无码影视| 亚洲国产美女视频| 亚洲Av熟妇高潮30p| 亚洲精品二区国产综合野狼| 色噜噜亚洲精品中文字幕| 亚洲18在线天美| 国产猛男猛女超爽免费视频| 57pao国产成视频免费播放| 国产片免费在线观看| 色噜噜亚洲精品中文字幕| 国产成人精品亚洲日本在线| 最近中文字幕2019高清免费| 亚洲精品成人网久久久久久| 久久精品国产亚洲av瑜伽| 久久WWW免费人成一看片| 狠狠色伊人亚洲综合成人| 无遮挡呻吟娇喘视频免费播放| 99久久99久久精品免费看蜜桃| 免费在线观看亚洲| 中文字幕亚洲精品| 亚洲国产无线乱码在线观看| 97碰公开在线观看免费视频| 亚洲av无码乱码国产精品fc2 | 国产99视频精品免费观看7| 国产亚洲?V无码?V男人的天堂| 亚洲AV日韩AV永久无码下载| 91在线免费视频| 中文字幕第13亚洲另类| 久久久久久久国产免费看| 无码国模国产在线观看免费| 苍井空亚洲精品AA片在线播放 | 亚洲AV无码成H人在线观看| 亚洲日本乱码在线观看| 好猛好深好爽好硬免费视频| 亚洲精品成人网久久久久久| 99在线视频免费观看| 亚洲国产精品无码久久久秋霞2 | 免费观看a级毛片| 亚洲丰满熟女一区二区哦| 波多野结衣免费视频观看| 牛牛在线精品观看免费正 |