antd vue3 (a-switch开关)

<template v-if="column.key === 'status'">
            <a-switch
              :disabled="!user.authorities.includes('schedule:update')"
              :loading="loading"
              :checked="record.status"
              :checked-value="1"
              :unchecked-value="2"
              @change="editStatus(record)"
            />
          </template>
checkedValue选中时的值
unCheckedValue非选中时的值
checked(v-model)指定当前是否选中
/** 修改用户状态 */
  const editStatus = async (row: InspectionScheduleDTO) => {
    loading = true
    const status = row.status === 1 ? 2 : 1

    try {
      await putInspectionScheduleEffective({
        id: row.id,
        status
      })
      row.status = status
      message.success('修改成功')
      reload()
    } catch (err: any) {
      message.error(err.message)
    } finally {
      loading = false
    }
  }

 const status = row.status === 1 ? 2 : 1   如果选中的值为1的话就把它变成2,否则就变成1

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
vue3 antdvue 中,要对 a-table 中的行进行合计,可以利用 a-table 中的 footer 属性和 scoped slot 的方式来实现。 为了得到每一行中需要合计的值,需要先将数据进行处理。 首先,需要在 a-table 中设置 footer 属性为 true,这样就会生成表格的 footer 部分。 然后,可以利用 scoped slot 来自定义 footer 行的内容。在 slot-scope 中,可以获取到表格中的所有数据,包括每一行中的数据。可以遍历每一行的数据,计算需要合计的值,并将结果显示在 footer 中。 下面是实现的代码示例: ``` <template> <a-table :columns="columns" :data-source="data" :footer="true"> <template v-slot:footer> <a-table-tfoot> <a-table-cell v-for="col in columns" :key="col.key"> <template v-if="col.key === 'total'"> {{ getFooterTotal(col.key) }} </template> <template v-else> {{ col.title }} </template> </a-table-cell> </a-table-tfoot> </template> </a-table> </template> <script> export default { data() { return { columns: [ { title: 'Name', dataIndex: 'name', key: 'name' }, { title: 'Age', dataIndex: 'age', key: 'age' }, { title: 'Address', dataIndex: 'address', key: 'address' }, { title: 'Total', key: 'total' }, ], data: [ { name: 'John', age: 28, address: 'New York', total: 100 }, { name: 'Jane', age: 32, address: 'London', total: 200 }, { name: 'Bob', age: 42, address: 'Paris', total: 300 }, ], }; }, methods: { getFooterTotal(key) { let total = 0; this.data.forEach((item) => { total += item[key]; }); return total; }, }, }; </script> ``` 在这个示例中,我们定义了一个 a-table ,包含了四列数据:Name、Age、Address 和 Total。其中,Total 列需要对其下面的每一行进行合计。 我们通过设置 footer 属性为 true,确保能够生成表格的 footer 部分。接着,我们可以利用 scoped slot 来自定义 footer 的内容。 在 footer 模板中,我们首先定义了一个 a-table-tfoot 元素,表示 footer 中要显示的行。 然后,我们遍历每一列数据,如果是 Total 列,就调用 getFooterTotal 方法来计算合计值。这个方法遍历每一行数据,将 Total 列的值累加到 total 中。 最后,我们将结果返回给 footer 模板,以显示在表格的 footer 中。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值