中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Vue表格首列相同數據合并怎么實現

發布時間:2023-04-20 16:14:54 來源:億速云 閱讀:198 作者:iii 欄目:開發技術

本文小編為大家詳細介紹“Vue表格首列相同數據合并怎么實現”,內容詳細,步驟清晰,細節處理妥當,希望這篇“Vue表格首列相同數據合并怎么實現”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學習新知識吧。

表格首列相同數據合并

1. 添加文件

1.src/views 下新建mergeCell.vue文件,代碼如下:

<template>
  <div id="app">
    <el-table
            :data="tableData"
            :span-method="(param)=>objectSpanMethod(param)"
            >
            <el-table-column
                prop="type_test"
                label="類型"               
                align='center'>
            </el-table-column>
            <el-table-column
                prop="type_spec"
                label="模塊"
                align='center'
                >
            </el-table-column>
            <el-table-column
                prop="is_execute"
                label="是否執行"
                align='center'
               >
                <template slot-scope="scope">
                    <span v-if="scope.row.is_execute == true">已執行</span>
                    <span v-if="scope.row.is_execute == false">未執行</span>
                </template>
            </el-table-column>
            <el-table-column
                prop="result_status"
                label="結果"
                align='center'
               >
                <template slot-scope='scope'>
                    <el-tag :type="scope.row.result_status | ResultFilter">
                        {{scope.row.result_status}}
                    </el-tag>
                </template>
            </el-table-column>
            <el-table-column
                prop="created_at"
                label="創建時間"
                align='center'
               >
                <template slot-scope="scope">
                {{ scope.row.created_at}}
            </template>
            </el-table-column>
        </el-table>
  </div>
</template>
<script>

export default {
    filters:{
        ResultFilter(status) {
        const ongSteadyMap = {
            SUCCESS: 'success',
            FAILURE: 'danger',
            NA: 'primary',
            ABORTED:'info',
            FAIL:'danger',
            None: 'warning'
      }
      return ongSteadyMap[status]
    },
      },
    data() {
        return {
            tableData:[
                {
                    "id": 1,
                    "created_at": "2023-06-18 11:51:07",
                    "updated_at": "2023-04-18 11:51:07",
                    "type_test": "功能測試",
                    "type_spec": "登錄",
                    "is_execute": true,
                    "result_status": "SUCCESS"
                },
                {
                    "id": 2,
                    "created_at": "2023-06-18 11:51:07",
                    "updated_at": "2023-06-18 11:51:07",
                    "type_test": "功能測試",
                    "type_spec": "退出",
                    "cr_id": "",
                    "is_execute": true,
                    "result_status": "SUCCESS"
                },
                {
                    "id": 3,
                    "created_at": "2023-06-18 11:51:07",
                    "updated_at": "2023-06-18 11:51:07",
                    "type_test": "接口測試",
                    "type_spec": "登錄",
                    "cr_id": "",
                    "is_execute": false,
                    "result_status": "N/A"
                },
                {
                    "id": 4,
                    "created_at": "2023-06-18 11:51:07",
                    "updated_at": "2023-06-18 11:51:07",
                    "type_test": "接口測試",
                    "type_spec": "退出",
                    "cr_id": "",
                    "is_execute": true,
                    "result_status": "FAIL"
                }
            ]
        };
    },
    methods: {
        objectSpanMethod({ row, column, rowIndex, columnIndex }) {
            console.log('objectSpanMethod',row, column, rowIndex, columnIndex)
            if (columnIndex === 0) {
                    const _row = this.flitterData(this.tableData).one[rowIndex];
                    const _col = _row > 0 ? 1 : 0;
                    return {
                        rowspan: _row,
                        colspan: _col,
                    };
		    }
        },
        flitterData(arr) {
            // 合并表格第一列
            let spanOneArr = [];
            let concatOne = 0;
            arr.forEach((item, index) => {

                if (index === 0) {
                    spanOneArr.push(1);
                    }
                else {
                    console.log('item',item,index)
                    console.log('arr',arr[index-1])
                    // 這里的type_test是表格綁定的字段,也就是需要合并的字段,根據自己的需求來改
                    if (item.type_test == arr[index -1].type_test) {
                        // 第一列需合并相同內容的判斷條件
                        spanOneArr[concatOne] += 1;
                        spanOneArr.push(0);
                    } else {
                        spanOneArr.push(1);
                        concatOne = index;
                    }

                }
            });
            return {
                one: spanOneArr,
            };
        },
        
    }
};
</script>

2. 添加路徑

在router下添加,如下路徑

{
    path: '/mergeCell',
    component: Layout,
    children: [
      {
        path: 'mergeCell',
        name: 'mergeCell',
        component: () => import('@/views/mergeCell.vue'),
        meta: { title: 'mergeCell', icon: 'form' }
      }
    ]
  },

3. 查看效果

npm run dev 運行,效果如下圖

Vue表格首列相同數據合并怎么實現

讀到這里,這篇“Vue表格首列相同數據合并怎么實現”文章已經介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領會,如果想了解更多相關內容的文章,歡迎關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

vue
AI

砀山县| 陆川县| 海口市| 德昌县| 佛冈县| 民丰县| 梅河口市| 陆川县| 武山县| 固阳县| 福建省| 曲松县| 绵竹市| 台山市| 政和县| 永嘉县| 泊头市| 卢龙县| 榕江县| 山东省| 高淳县| 伊金霍洛旗| 稻城县| 尤溪县| 江川县| 祥云县| 密云县| 渑池县| 德钦县| 曲阳县| 宁都县| 重庆市| 秦皇岛市| 延安市| 安西县| 辽中县| 阳新县| 佛冈县| 湛江市| 长沙县| 孟州市|