vue單元格多列合并的實(shí)現(xiàn)
一.多列合并
1.在el-table中添加:span-method='objectSpanMethod'屬性來(lái)控制合并單元格,如下圖
2.合并代碼,每一列都要設(shè)置一個(gè)不同的key,這樣可以防止合并的時(shí)候上下內(nèi)容一樣導(dǎo)致錯(cuò)誤的問(wèn)題
objectSpanMethod({ row, column, rowIndex, columnIndex }) { if (columnIndex === 0) { if (this.myObj[row.channel_type].start === rowIndex) { return { rowspan: this.myObj[row.channel_type].step, colspan: 1 }; } else { return { rowspan: 0, colspan: 0 }; } } if (columnIndex === 1) { if ( this.myObj_two[row.channel_name_chinese + row.channel_type].start === rowIndex ) { return { rowspan: this.myObj_two[row.channel_name_chinese + row.channel_type] .step, colspan: 1 }; } else { return { rowspan: 0, colspan: 0 }; } } }, // 合并單元格第一列 resolveData(arr) { var obj = {}; arr.forEach((val, key) => { if (!obj[val.channel_type]) { obj[val.channel_type] = { start: key, step: 1 }; } else { obj[val.channel_type].step++; } }); this.myObj = obj; console.log(obj); }, // 合并單元格第二列 resolveData_two(arr) { var obj = {}; arr.forEach((val, key) => { if (!obj[val.channel_name_chinese + val.channel_type]) { obj[val.channel_name_chinese + val.channel_type] = { start: key, step: 1 }; } else { obj[val.channel_name_chinese + val.channel_type].step++; } }); this.myObj_two = obj; console.log(this.myObj_two, 'this.myObj'); },
3.需要調(diào)用一下下面兩個(gè)函數(shù),data為你所獲取的所有數(shù)據(jù)
this.resolveData_two(data); this.resolveData(data);
4.合并結(jié)果如下圖
到此這篇關(guān)于vue單元格多列合并的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)vue單元格多列合并內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. JSP數(shù)據(jù)交互實(shí)現(xiàn)過(guò)程解析2. 解決啟動(dòng)django,瀏覽器顯示“服務(wù)器拒絕訪問(wèn)”的問(wèn)題3. JavaMail 1.4 發(fā)布4. vue使用webSocket更新實(shí)時(shí)天氣的方法5. 淺談python出錯(cuò)時(shí)traceback的解讀6. Python importlib動(dòng)態(tài)導(dǎo)入模塊實(shí)現(xiàn)代碼7. Yii2.0引入CSS,JS文件方法8. Nginx+php配置文件及原理解析9. 關(guān)于HTML5的img標(biāo)簽10. 如何使用CSS3畫出一個(gè)叮當(dāng)貓
