antd-pro项目开发问题
antd-pro项目开发中遇到的控制台报错问题。
-
Warning: Cannot update a component (
ForwardRef(TableModule)
) while rendering a different component (Cell
). To locate the bad setState() call insideCell
, follow the stack trace as described in https://fb.me/setstate-in-render
in Cell (created by BodyRow);原因:表头操作项使用了useState操作
示例:
-
index.js:1 Warning: Each child in a list should have a unique “key” prop. See https://fb.me/react-warning-keys for more information. in tbody (created by Body)
原因:table 唯一key值,操作项需加key,涉及循环的都需要加key,只在最外层标签起作用
示例:
-
滚动页面,下拉框会滚动至页面上方
示例
解决方法:
为组件添加属性
getPopupContainer={triggerNode => triggerNode.parentNode}
时间选择器需要添加
getCalendarContainer={triggerNode => triggerNode.parentNode} -
文件上传格式限制
示例:
beforeUpload(file) {
return new Promise(function (resolve, reject) {
if (file.type !== “application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”) {
message.error(请选择样本模板且只允许上传.xlsx文件!
)
reject()
} else {
resolve()
}
})
}