亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue+el-table實(shí)現(xiàn)合并單元格

 更新時(shí)間:2021年09月29日 09:24:37   作者:linlinlinhtml_  
這篇文章主要為大家詳細(xì)介紹了vue+el-table實(shí)現(xiàn)合并單元格,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了el-table實(shí)現(xiàn)合并單元格的具體代碼,供大家參考,具體內(nèi)容如下

el-table合并單元格(vue+element)

- 先在el-table放入:span-method="arraySpanMethod"

<el-table :header-cell-style="{background:'#eef1f6',color:'#606266'}" :data="merchantList" border :span-method="arraySpanMethod">
          <el-table-column align="center" prop="provinceName" label="省份"> </el-table-column>
          <el-table-column align="center" label="代理商名稱">
            <template scope="scope">
              <span>{{scope.row.parentMerchantName == scope.row.merchantName ? '---' : scope.row.parentMerchantName}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="cityName" label="市"> </el-table-column>
          <el-table-column align="center" prop="countryName" label="區(qū)"> </el-table-column>
          <el-table-column align="center" prop="merchantName" label="門(mén)店"> </el-table-column>
</el-table>

在methods中寫(xiě)入方法:

//合并單元格
arraySpanMethod ({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {//第一列的合并方法,省
        const _row_1 = this.provinceArr[rowIndex];
        const _col_1 = _row_1 > 0 ? 1 : 0; //如果被合并了_row=0則它這個(gè)列需要取消
        return {
          rowspan: _row_1,
          colspan: _col_1
        }
      } 
    },
    //初始化
    merageInit () {
      this.provinceArr = []
      this.provincePos = 0
    },
    //要合并的數(shù)組的方法
    merage () {
      this.merageInit()
      for (var i = 0; i < this.merchantList.length; i++) {
        if (i === 0) {
          //第一行必須存在
          this.provinceArr.push(1)
          this.provincePos = 0
        } else {
          // 判斷當(dāng)前元素與上一個(gè)元素是否相同 this.provincePos是provinceArr內(nèi)容的序號(hào)
          //省
          if (this.merchantList[i].provinceName === this.merchantList[i - 1].provinceName) {
            this.provinceArr[this.provincePos] += 1
            this.provinceArr.push(0)
          } else {
            this.provinceArr.push(1)
            this.provincePos = i
          }
        }
      }
    },

結(jié)果展示:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論