refactor(Icon): use setup

This commit is contained in:
chenjiahan 2020-08-23 13:09:52 +08:00
parent 1b96a45d0b
commit 785047754b

View File

@ -24,25 +24,24 @@ export default createComponent({
}, },
}, },
render() { setup(props, { slots }) {
const { name } = this; return () => {
const imageIcon = isImage(name); const { tag, dot, name, size, badge, color, classPrefix } = props;
const isImageIcon = isImage(name);
return ( return (
<this.tag <tag
class={[ class={[classPrefix, isImageIcon ? '' : `${classPrefix}-${name}`]}
this.classPrefix,
imageIcon ? '' : `${this.classPrefix}-${name}`,
]}
style={{ style={{
color: this.color, color,
fontSize: addUnit(this.size), fontSize: addUnit(size),
}} }}
> >
{this.$slots.default?.()} {slots.default?.()}
{imageIcon && <img class={bem('image')} src={name} />} {isImageIcon && <img class={bem('image')} src={name} />}
<Badge dot={this.dot} badge={this.badge} /> <Badge dot={dot} badge={badge} />
</this.tag> </tag>
); );
};
}, },
}); });