vue3 串联表格 匹配上方和左侧(个人笔记)

 页面代码

<template>
  <div class="layout-container">
    <div class="box2">
      <h4>库存支撑分析:</h4>
      <div class="justify-content-end">
        <el-button>获取接单量</el-button>
      </div>
      <el-table :data="tableData1" style="width: 100%"> //element tabel表格组件绑定数据源
        <el-table-column prop="name" label="数量" />
        <el-table-column v-if="tableData1.length > 0" v-for="(item, k) in                         
          tableData1[0].data" :key="item.id" :label="item.month + '月'">
          <el-table-column label="目标">
            <template #default="scope"> // 展示不同的数据
              {{ tableData1[0].data[k][scope.row.key] }}
            </template>
          </el-table-column>
          <el-table-column label="实际" v-if="k <= 1">
            <template #default="scope"> // 展示不同的数据
              {{ tableData1[0].data[k][scope.row.key1] }}
            </template>
          </el-table-column>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

数据处理代码

<script lang="ts">
import { defineComponent, ref } from "vue";
import { materialpropcur } from "@/api/Mdse"; //这里是我调取的接口
export default defineComponent({
  setup() {
    let tableData1 = ref([]); //数据源
    //调取接口处理数据
    materialpropcur().then((res) => {
      console.log(res.data);
        // 添加区别key 
      let newArr = [
        { name: "接单量", data: [], key: "orderObjective", key1: "orderFact" },
        { name: "出货量", data: [], key: "outQty", key1: "realityOutQty" },
        { name: "可用库存", data: [], key: "factQty", key1: "realityFactQty" },
        { name: "呆滞库存", data: [], key: "dullQty", key1: "realityDullQty" },
        { name: "月产能需求", data: [], key: "capacityQty", key1: "realityCapacityQty" },
        { name: "现月可生产量", data: [], key: "outputQty", key1: "realityOutputQty" },
        { name: "产能负荷", data: [], key: "orderObjective", key1: "orderFact" },
      ];
        // 这里每一条data都有所有的数据 用Key和key1来获取所需要的
      newArr.forEach((item) => {
        res.data.forEach((item1) => {
          item.data.push(item1);
        });
      });
      console.log(newArr);
      tableData1.value = newArr;
      console.log(tableData1.value);
    });
    return {
      tableData1,
    };
  },
});
</script>

css

<style lang="scss" scoped>
.layout-container {
  padding: 10px;
  .justify-content-end {
    display: flex;
    justify-content: end;
  }
  .box2 {
    width: 100%;
    height: 100%;
  }
}
</style>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值