Skip to content

feat: update avatar #2372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions components/avatar/Avatar.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { inject } from 'vue';
import { ConfigConsumerProps } from '../config-provider';
import { getListeners, getComponentFromProp } from '../_util/props-util';
import { getComponent } from '../_util/props-util';
import PropTypes from '../_util/vue-types';

export default {
Expand All @@ -26,8 +27,10 @@ export default {
alt: String,
loadError: Function,
},
inject: {
configProvider: { default: () => ConfigConsumerProps },
setup() {
return {
configProvider: inject('configProvider', ConfigConsumerProps),
};
},
data() {
return {
Expand Down Expand Up @@ -87,7 +90,7 @@ export default {
},
render() {
const { prefixCls: customizePrefixCls, shape, size, src, alt, srcSet } = this.$props;
const icon = getComponentFromProp(this, 'icon');
const icon = getComponent(this, 'icon');
const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('avatar', customizePrefixCls);

Expand Down Expand Up @@ -116,7 +119,7 @@ export default {
}
: {};

let children = this.$slots.default;
let children = this.$slots.default && this.$slots.default();
if (src && isImgExist) {
children = <img src={src} srcSet={srcSet} onError={this.handleImgLoadError} alt={alt} />;
} else if (icon) {
Expand Down Expand Up @@ -158,7 +161,7 @@ export default {
}
}
return (
<span ref="avatarNode" {...{ on: getListeners(this), class: classString, style: sizeStyle }}>
<span ref="avatarNode" {...{ class: classString, style: sizeStyle }}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以直接改成

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK~

{children}
</span>
);
Expand Down
6 changes: 2 additions & 4 deletions components/avatar/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import Avatar from './Avatar';
import Base from '../base';

/* istanbul ignore next */
Avatar.install = function(Vue) {
Vue.use(Base);
Vue.component(Avatar.name, Avatar);
Avatar.install = function(app) {
app.component(Avatar.name, Avatar);
};

export default Avatar;
2 changes: 2 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '@babel/polyfill';
import { createApp } from 'vue';
import App from './App.vue';
import Avatar from 'ant-design-vue/avatar';
import Button from 'ant-design-vue/button';
import Drawer from 'ant-design-vue/drawer';
import Affix from 'ant-design-vue/affix';
Expand All @@ -11,6 +12,7 @@ import Empty from 'ant-design-vue/empty';
import 'ant-design-vue/style.js';

createApp(App)
.use(Avatar)
.use(Button)
.use(ConfigProvider)
.use(Drawer)
Expand Down