【ant-table绑定值变化页面不更新,报错Cannot read properties of undefined (reading ‘__asyncLoader‘)】

a-table绑定值变化,报错Cannot read properties of undefined reading '__asyncLoader'

问题背景: vue3项目中使用ant-design-vue中的a-table,data-source绑定值为"tableData",页面加载时调用接口获得tableData显示正常,当输入筛选条件重新搜索后获得新的tableData,此时打印tableData值已经更新,但是页面没有变化,并报Cannot read properties of undefined reading '__asyncLoader'错误。

解决思路: 一开始以为值覆盖的问题,但是写死数据仍然报错,把template slot代码均注释掉,逐步排查找了两天没有找到问题,后面把a-table注释掉,改用list发现不报错,最终确定了是a-table中插槽的问题

解决方法: vue3中a-table不在使用scopedSlots插槽,改用v-slot:bodyCell的形式使用插槽

1. 原代码

<a-table class="table" row-key="userId"
            :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" :columns="tableHead"
            :data-source="tableData" :pagination="pagination" @change="handleTableChange">
            <template slot="userName" slot-scope="userName,record">
              <span style="color: #1890FF;cursor:pointer;" @click="handleDetails(record.userId)">{{ userName }}</span>
            </template>
            <template slot="dept" slot-scope="dept">
              {{ dept ? dept.deptName : '' }}
            </template>
            <template slot="posts" slot-scope="posts">
              <!-- {{ posts | showPosts }} -->
              {{posts[0].postName}}
            </template>
            <template slot="status" slot-scope="status, record">
              <a-switch :checked="record.status === '0'" checked-children="启用" un-checked-children="禁用"
                @change="handleChange(status,record)" />
            </template>
            <template slot="option" slot-scope="state, record">
              <a-button type="link" @click="handleUpdate(record.userId)">编辑</a-button>
              <a-button type="link" @click="handleDelete(record.userId)">删除</a-button>
              <a-button type="link" @click="handleEquipment(record.userId)">设备权限</a-button>
              <a-button type="link" @click="resetPassword(record.userId)">重置密码</a-button>
            </template>
          </a-table>

在这里插入图片描述

2. 更改后的代码

<a-table
            class="table"
            :columns="tableHead"
            rowKey="userId"
            :data-source="tableData"
            :pagination="pagination"
            :row-selection="{
              selectedRowKeys: selectedRowKeys,
              onChange: onSelectChange,
            }"
            @change="handleTableChange"
          >
            <template v-slot:bodyCell="{ column, record, index }">
              <template v-if="column.dataIndex == 'userName'">
                <span
                  style="color: #1890ff; cursor: pointer"
                  @click="handleDetails(record.userId)"
                  >{{ record.userName }}</span
                >
              </template>
              <template v-if="column.dataIndex == 'dept'">
                {{ record.dept ? record.dept.deptName : "" }}
              </template>
              <template v-if="column.dataIndex == 'status'">
                <a-switch
                  :checked="record.status === '0'"
                  checked-children="启用"
                  un-checked-children="禁用"
                  @change="handleChange(record.status, record)"
                />
              </template>
              <template v-if="column.dataIndex == 'posts'">
                {{ record.posts ? record.posts[0].postName : "" }}
              </template>
              <template v-if="column.dataIndex == 'option'">
                <a-button type="link" @click="handleUpdate(record.userId)">编辑</a-button>
                <a-button type="link" @click="handleDelete(record.userId)">删除</a-button>
                <a-button type="link" @click="handleEquipment(record.userId)"
                  >设备权限</a-button
                >
                <a-button type="link" @click="resetPasswords(record.userId)"
                  >重置密码</a-button
                >
              </template>
            </template>
          </a-table>

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

trabecula_hj

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值