mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 11:39:28 +08:00
fix: should show children if src is not exist, close: #6804
This commit is contained in:
parent
02fa2cd672
commit
b45bf6d814
@ -31,6 +31,7 @@ export default class Avatar extends React.Component<AvatarProps, any> {
|
||||
super(props);
|
||||
this.state = {
|
||||
scale: 1,
|
||||
isImgExist: true,
|
||||
};
|
||||
}
|
||||
|
||||
@ -63,6 +64,8 @@ export default class Avatar extends React.Component<AvatarProps, any> {
|
||||
}
|
||||
}
|
||||
|
||||
handleImgLoadError = () => this.setState({ isImgExist: false });
|
||||
|
||||
render() {
|
||||
const {
|
||||
prefixCls, shape, size, src, icon, className, ...others,
|
||||
@ -80,8 +83,13 @@ export default class Avatar extends React.Component<AvatarProps, any> {
|
||||
});
|
||||
|
||||
let children = this.props.children;
|
||||
if (src) {
|
||||
children = <img src={src} />;
|
||||
if (src && this.state.isImgExist) {
|
||||
children = (
|
||||
<img
|
||||
src={src}
|
||||
onError={this.handleImgLoadError}
|
||||
/>
|
||||
);
|
||||
} else if (icon) {
|
||||
children = <Icon type={icon} />;
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user