mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
refactor(Loading): refactor with composition api
This commit is contained in:
parent
a528023405
commit
ce27bcdf9b
@ -1,23 +1,12 @@
|
|||||||
// Utils
|
import { computed } from 'vue';
|
||||||
import { createNamespace, addUnit } from '../utils';
|
import { createNamespace, addUnit } from '../utils';
|
||||||
|
|
||||||
const [createComponent, bem] = createNamespace('loading');
|
const [createComponent, bem] = createNamespace('loading');
|
||||||
|
|
||||||
const SpinIcon = [];
|
|
||||||
for (let i = 0; i < 12; i++) {
|
|
||||||
SpinIcon.push(<i />);
|
|
||||||
}
|
|
||||||
|
|
||||||
const CircularIcon = (
|
|
||||||
<svg class={bem('circular')} viewBox="25 25 50 50">
|
|
||||||
<circle cx="50" cy="50" r="20" fill="none" />
|
|
||||||
</svg>
|
|
||||||
);
|
|
||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
props: {
|
props: {
|
||||||
color: String,
|
|
||||||
size: [Number, String],
|
size: [Number, String],
|
||||||
|
color: String,
|
||||||
vertical: Boolean,
|
vertical: Boolean,
|
||||||
textSize: [Number, String],
|
textSize: [Number, String],
|
||||||
type: {
|
type: {
|
||||||
@ -26,39 +15,58 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
setup(props, { slots }) {
|
||||||
genLoadingText() {
|
const SpinIcon = [];
|
||||||
if (this.$slots.default) {
|
for (let i = 0; i < 12; i++) {
|
||||||
const style = this.textSize && {
|
SpinIcon.push(<i />);
|
||||||
fontSize: addUnit(this.textSize),
|
}
|
||||||
};
|
|
||||||
|
|
||||||
|
const CircularIcon = (
|
||||||
|
<svg class={bem('circular')} viewBox="25 25 50 50">
|
||||||
|
<circle cx="50" cy="50" r="20" fill="none" />
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
|
||||||
|
const renderText = () => {
|
||||||
|
if (slots.default) {
|
||||||
return (
|
return (
|
||||||
<span class={bem('text')} style={style}>
|
<span
|
||||||
{this.$slots.default()}
|
class={bem('text')}
|
||||||
|
style={{
|
||||||
|
fontSize: addUnit(props.textSize),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{slots.default()}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
},
|
|
||||||
|
|
||||||
render() {
|
const spinnerStyle = computed(() => {
|
||||||
const { color, size, type, vertical } = this;
|
const style = {
|
||||||
|
color: props.color,
|
||||||
|
};
|
||||||
|
|
||||||
const style = { color };
|
if (props.size) {
|
||||||
if (size) {
|
const size = addUnit(props.size);
|
||||||
const iconSize = addUnit(size);
|
style.width = size;
|
||||||
style.width = iconSize;
|
style.height = size;
|
||||||
style.height = iconSize;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return style;
|
||||||
<div class={bem([type, { vertical }])}>
|
});
|
||||||
<span class={bem('spinner', type)} style={style}>
|
|
||||||
{type === 'spinner' ? SpinIcon : CircularIcon}
|
return () => {
|
||||||
</span>
|
const { type, vertical } = props;
|
||||||
{this.genLoadingText()}
|
|
||||||
</div>
|
return (
|
||||||
);
|
<div class={bem([type, { vertical }])}>
|
||||||
|
<span class={bem('spinner', type)} style={spinnerStyle.value}>
|
||||||
|
{type === 'spinner' ? SpinIcon : CircularIcon}
|
||||||
|
</span>
|
||||||
|
{renderText()}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user