diff --git a/src/loading/index.js b/src/loading/index.js index 445cfb383..bbfa0cf9a 100644 --- a/src/loading/index.js +++ b/src/loading/index.js @@ -1,23 +1,12 @@ -// Utils +import { computed } from 'vue'; import { createNamespace, addUnit } from '../utils'; const [createComponent, bem] = createNamespace('loading'); -const SpinIcon = []; -for (let i = 0; i < 12; i++) { - SpinIcon.push(); -} - -const CircularIcon = ( - - - -); - export default createComponent({ props: { - color: String, size: [Number, String], + color: String, vertical: Boolean, textSize: [Number, String], type: { @@ -26,39 +15,58 @@ export default createComponent({ }, }, - methods: { - genLoadingText() { - if (this.$slots.default) { - const style = this.textSize && { - fontSize: addUnit(this.textSize), - }; + setup(props, { slots }) { + const SpinIcon = []; + for (let i = 0; i < 12; i++) { + SpinIcon.push(); + } + const CircularIcon = ( + + + + ); + + const renderText = () => { + if (slots.default) { return ( - - {this.$slots.default()} + + {slots.default()} ); } - }, - }, + }; - render() { - const { color, size, type, vertical } = this; + const spinnerStyle = computed(() => { + const style = { + color: props.color, + }; - const style = { color }; - if (size) { - const iconSize = addUnit(size); - style.width = iconSize; - style.height = iconSize; - } + if (props.size) { + const size = addUnit(props.size); + style.width = size; + style.height = size; + } - return ( -
- - {type === 'spinner' ? SpinIcon : CircularIcon} - - {this.genLoadingText()} -
- ); + return style; + }); + + return () => { + const { type, vertical } = props; + + return ( +
+ + {type === 'spinner' ? SpinIcon : CircularIcon} + + {renderText()} +
+ ); + }; }, });