Umi-antd后台管理遇到的坑
作者:互联网
1.在用到antd里面的tree/treeSelect组件的时候,不能将带有tree的子组件放在父组件里面写,不然会出现点击tree组件,子组件重新渲染的问题(刷新/闪动),解决办法 子组件放在父组件外面,通过传值的方法实现,如果子组件中需要控制模态框=>
父组件
<a onClick={() => handleRoleModalVisible(true, record)} style={{color: 'orange'}}>授权</a>
//授权树展示
const handleRoleModalVisible = (RoleModelVisibel: boolean, record?: any) => {
setRoleModalVisible(RoleModelVisibel);
// console.log(record)
if(RoleModelVisibel==undefined){
setroleAuth(undefined)
}else{
setroleAuth(record || {})
}
};
子组件
const {roleAuth, treeData, roleModalVisible, handleRoleModalVisible} = props;
const handleAuthOk = () => {
Authorization({role_id: roleAuth.roleId, checkedKeys})
.then(()=> {
// console.log(res.data)
message.success('授权成功')
})
.catch(() => {
message.error('授权失败')
})
handleRoleModalVisible(false)
};
<Modal
maskClosable={false}
destroyOnClose
title="角色授权"
visible={roleModalVisible}
onOk={handleAuthOk}
onCancel={() => handleRoleModalVisible()}
okText="确认"
cancelText="取消"
>
2.post请求接口如果需要传参,body形式的,接口这样写
//角色授权
export async function Authorization(params:any): Promise<any> {
return request.post(`...`,params.checkedKeys)
}
请求接口时:
Authorization({checkedKeys})
.then(()=> {
// console.log(res.data)
message.success('授权成功')
})
.catch(() => {
message.error('授权失败')
})
标签:const,record,handleRoleModalVisible,组件,授权,后台,antd,message,Umi 来源: https://blog.csdn.net/weixin_47769562/article/details/121222802