el-table里的状态切换

项目中的一个小块,记下来以后要是遇到用方便一点
在这里插入图片描述
html

<el-table :data="tableData" stripe style="width: 100%">
          <el-table-column
            prop="date"
            label="日程表"
            align="center"
            class-name="weekdays"
            width="100"
          >
          </el-table-column>
          <el-table-column label="上午" align="center">
            <template slot-scope="scope">
              <div v-for="(ele, index) in scope.row.am.title" :key="index">
                <span
                  v-if="index == scope.row.am.currentId"
                  style="
                    display: inline-block;
                    margin-left: 10px;
                    cursor: pointer;
                  "
                  >{{ ele }}
                </span>
                <div class="myToggle" v-if="index == scope.row.am.currentId">
                  <div class="upper" @click="change(scope.row.id, 'am')"></div>
                  <div class="lower" @click="change(scope.row.id, 'am')"></div>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="pm" label="下午" align="center">
            <template slot-scope="scope">
              <div v-for="(ele, index) in scope.row.pm.title" :key="index">
                <span
                  v-if="index == scope.row.pm.currentId"
                  style="
                    display: inline-block;
                    margin-left: 10px;
                    cursor: pointer;
                  "
                  >{{ ele }}
                </span>
                <div class="myToggle" v-if="index == scope.row.pm.currentId">
                  <div class="upper" @click="change(scope.row.id, 'pm')"></div>
                  <div class="lower" @click="change(scope.row.id, 'pm')"></div>
                </div>
              </div>
            </template>
          </el-table-column>
        </el-table>

js

 tableData: [
    {
      id: 0,
      date: "周一",
      am: {
        currentId: 0,
        title: ["休息", "坐诊"],
      },
      pm: {
        currentId: 0,
        title: ["休息", "坐诊"],
      },
    },
    {
      id: 1,
      date: "周二",
      am: {
        currentId: 0,
        title: ["休息", "坐诊"],
      },
      pm: {
        currentId: 0,
        title: ["休息", "坐诊"],
      },
    },
    {
      id: 2,
      date: "周三",
      am: {
        currentId: 0,
        title: ["休息", "坐诊"],
      },
      pm: {
        currentId: 0,
        title: ["休息", "坐诊"],
      },
    },
    {
      id: 3,
      date: "周四",
      am: {
        currentId: 0,
        title: ["休息", "坐诊"],
      },
      pm: {
        currentId: 0,
        title: ["休息", "坐诊"],
      },
    },
    {
      id: 4,
      date: "周五",
      am: {
        currentId: 0,
        title: ["休息", "坐诊"],
      },
      pm: {
        currentId: 0,
        title: ["休息", "坐诊"],
      },
    },
    {
      id: 5,
      date: "周六",
      am: {
        currentId: 0,
        title: ["休息", "坐诊"],
      },
      pm: {
        currentId: 0,
        title: ["休息", "坐诊"],
      },
    },
    {
      id: 6,
      date: "周日",
      am: {
        currentId: 0,
        title: ["休息", "坐诊"],
      },
      pm: {
        currentId: 0,
        title: ["休息", "坐诊"],
      },
    },
  ]

   change(row, col) {
      //   console.log(this.tableData[row][col])
      this.tableData[row][col].currentId = !this.tableData[row][col].currentId;
    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值