Skip to content

Commit 4ef17f8

Browse files
authored
feat: update avatar (#2372)
1 parent d00a971 commit 4ef17f8

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

components/avatar/Avatar.jsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { inject } from 'vue';
12
import { ConfigConsumerProps } from '../config-provider';
2-
import { getListeners, getComponentFromProp } from '../_util/props-util';
3+
import { getComponent } from '../_util/props-util';
34
import PropTypes from '../_util/vue-types';
45

56
export default {
@@ -26,8 +27,10 @@ export default {
2627
alt: String,
2728
loadError: Function,
2829
},
29-
inject: {
30-
configProvider: { default: () => ConfigConsumerProps },
30+
setup() {
31+
return {
32+
configProvider: inject('configProvider', ConfigConsumerProps),
33+
};
3134
},
3235
data() {
3336
return {
@@ -87,7 +90,7 @@ export default {
8790
},
8891
render() {
8992
const { prefixCls: customizePrefixCls, shape, size, src, alt, srcSet } = this.$props;
90-
const icon = getComponentFromProp(this, 'icon');
93+
const icon = getComponent(this, 'icon');
9194
const getPrefixCls = this.configProvider.getPrefixCls;
9295
const prefixCls = getPrefixCls('avatar', customizePrefixCls);
9396

@@ -116,7 +119,7 @@ export default {
116119
}
117120
: {};
118121

119-
let children = this.$slots.default;
122+
let children = this.$slots.default && this.$slots.default();
120123
if (src && isImgExist) {
121124
children = <img src={src} srcSet={srcSet} onError={this.handleImgLoadError} alt={alt} />;
122125
} else if (icon) {
@@ -158,7 +161,7 @@ export default {
158161
}
159162
}
160163
return (
161-
<span ref="avatarNode" {...{ on: getListeners(this), class: classString, style: sizeStyle }}>
164+
<span ref="avatarNode" {...{ class: classString, style: sizeStyle }}>
162165
{children}
163166
</span>
164167
);

components/avatar/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import Avatar from './Avatar';
2-
import Base from '../base';
32

43
/* istanbul ignore next */
5-
Avatar.install = function(Vue) {
6-
Vue.use(Base);
7-
Vue.component(Avatar.name, Avatar);
4+
Avatar.install = function(app) {
5+
app.component(Avatar.name, Avatar);
86
};
97

108
export default Avatar;

examples/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import '@babel/polyfill';
22
import { createApp } from 'vue';
33
import App from './App.vue';
4+
import Avatar from 'ant-design-vue/avatar';
45
import Button from 'ant-design-vue/button';
56
import Comment from 'ant-design-vue/comment';
67
import Drawer from 'ant-design-vue/drawer';
@@ -15,6 +16,7 @@ import Timeline from 'ant-design-vue/timeline';
1516
import 'ant-design-vue/style.js';
1617

1718
createApp(App)
19+
.use(Avatar)
1820
.use(Button)
1921
.use(Comment)
2022
.use(ConfigProvider)

0 commit comments

Comments
 (0)