注如toggleRowSelection方法没有效果并需要调用后台接口的情况下,请在回调完成之后操作
import { useBatchAffairInfoStore } from "@/store"; const store = useBatchAffairInfoStore() // 选择事务下一步操作 const onNext = () => { //存入pinia操作 store.storageBatchAffairList(multipleSelection.value) router.push('/home/synergy/batch/choseOperation') } const affairTableRef = ref<InstanceType<typeof ElTable>>() const SynergyIssuesChildList = ref<any>([]) const getSynergyManagerSynergyIssuesChildIssuesListServiceData = async () => { const res = await reqSynergyManagerSynergyIssuesChildIssuesListService({ synergy_issues_id: 1 }) if (res.code !== 0) return ElMessage.error(res.message); SynergyIssuesChildList.value = res.data let deconstructionData = [...store.batchAffairInfoList] // 列表选中数据回显 nextTick(() => { SynergyIssuesChildList.value.forEach((item: any) => { let result = deconstructionData.find(row => row.id == item.id); if (result) { affairTableRef.value!.toggleRowSelection(item, true) } }); });
以下是pinia代码方法
// import type { UserInfoTypeInterFace } from '@/types/login'; import { defineStore } from 'pinia' import { ref } from "vue"; export const useBatchAffairInfoStore = defineStore('batchAffairInfoList', () => { // 存储批量事务数据 const batchAffairInfoList = ref<any>([]) const storageBatchAffairList = (data: any) => { batchAffairInfoList.value = data } return { batchAffairInfoList, storageBatchAffairList } }, { persist: true })
别忘了导出pinia文件
注:如有不好的地方体谅体谅,有好的建议欢迎提出来
上述是个人理解。描述不恰当的地方欢迎指正。一起进步~