chore(Tag): code review

This commit is contained in:
chenjiahan 2020-09-27 16:53:29 +08:00
parent 1c020a9dac
commit da0d5435de

View File

@ -1,4 +1,4 @@
import { computed, Transition } from 'vue'; import { Transition } from 'vue';
import { createNamespace } from '../utils'; import { createNamespace } from '../utils';
import Icon from '../icon'; import Icon from '../icon';
@ -31,16 +31,17 @@ export default createComponent({
emit('close'); emit('close');
}; };
const style = computed(() => { const getStyle = () => {
const key = props.plain ? 'color' : 'backgroundColor'; if (props.plain) {
const style = { [key]: props.color }; return {
color: props.textColor || props.color,
if (props.textColor) { };
style.color = props.textColor;
} }
return {
return style; color: props.textColor,
}); background: props.color,
};
};
return () => { return () => {
const { show, type, mark, plain, round, size, closeable } = props; const { show, type, mark, plain, round, size, closeable } = props;
@ -55,13 +56,13 @@ export default createComponent({
); );
return ( return (
<Transition name={closeable ? 'van-fade' : null}> <Transition name={closeable ? 'van-fade' : undefined}>
{show && ( {show ? (
<span style={style.value} class={bem([classes, type])}> <span style={getStyle()} class={bem([classes, type])}>
{slots.default?.()} {slots.default?.()}
{CloseIcon} {CloseIcon}
</span> </span>
)} ) : null}
</Transition> </Transition>
); );
}; };