From 9063d17f8b2a305d4276454b17243e56f38b68a5 Mon Sep 17 00:00:00 2001 From: tanjinzhou <415800467@qq.com> Date: Thu, 4 Jun 2020 18:35:33 +0800 Subject: [PATCH] feat: update spin --- components/_util/props-util.js | 2 +- components/spin/Spin.jsx | 43 +++++++++++++--------------------- package.json | 1 - 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/components/_util/props-util.js b/components/_util/props-util.js index 52e40f70c..195eb1c63 100644 --- a/components/_util/props-util.js +++ b/components/_util/props-util.js @@ -127,7 +127,7 @@ const getComponent = (instance, prop, options = instance, execute = true) => { if (temp !== undefined) { return typeof temp === 'function' && execute ? temp(options) : temp; } else { - let com = instance.$slots[prop] || null; + let com = instance.$slots[prop]; com = execute && com ? com(options) : com; return Array.isArray(com) && com.length === 1 ? com[0] : com; } diff --git a/components/spin/Spin.jsx b/components/spin/Spin.jsx index 51e2d6819..50d3cfef4 100644 --- a/components/spin/Spin.jsx +++ b/components/spin/Spin.jsx @@ -1,14 +1,8 @@ -import { inject, cloneVNode } from 'vue'; +import { inject, cloneVNode, isVNode } from 'vue'; import debounce from 'lodash/debounce'; import PropTypes from '../_util/vue-types'; import BaseMixin from '../_util/BaseMixin'; -import { - filterEmpty, - initDefaultProps, - isValidElement, - getComponent, - getListeners, -} from '../_util/props-util'; +import { filterEmpty, initDefaultProps, getComponent } from '../_util/props-util'; import { ConfigConsumerProps } from '../config-provider'; export const SpinSize = PropTypes.oneOf(['small', 'default', 'large']); @@ -31,17 +25,19 @@ function shouldDelay(spinning, delay) { } export function setDefaultIndicator(Content) { + const Indicator = Content.indicator; defaultIndicator = - typeof Content.indicator === 'function' - ? Content.indicator - : h => { - return ; + typeof Indicator === 'function' + ? Indicator + : () => { + return ; }; } export default { name: 'ASpin', mixins: [BaseMixin], + inheritAttrs: false, props: initDefaultProps(SpinProps(), { size: 'default', spinning: true, @@ -95,7 +91,7 @@ export default { }, getChildren() { if (this.$slots && this.$slots.default) { - return filterEmpty(this.$slots.default); + return filterEmpty(this.$slots.default()); } return null; }, @@ -111,11 +107,11 @@ export default { indicator = filterEmpty(indicator); indicator = indicator.length === 1 ? indicator[0] : indicator; } - if (isValidElement(indicator)) { + if (isVNode(indicator)) { return cloneVNode(indicator, { class: dotClassName }); } - if (defaultIndicator && isValidElement(defaultIndicator(h))) { + if (defaultIndicator && isVNode(defaultIndicator(h))) { return cloneVNode(defaultIndicator(h), { class: dotClassName }); } @@ -130,13 +126,8 @@ export default { }, }, render(h) { - const { - size, - prefixCls: customizePrefixCls, - tip, - wrapperClassName, - ...restProps - } = this.$props; + const { size, prefixCls: customizePrefixCls, tip, wrapperClassName } = this.$props; + const { class: cls, style, ...divProps } = this.$attrs; const getPrefixCls = this.configProvider.getPrefixCls; const prefixCls = getPrefixCls('spin', customizePrefixCls); @@ -147,10 +138,11 @@ export default { [`${prefixCls}-lg`]: size === 'large', [`${prefixCls}-spinning`]: sSpinning, [`${prefixCls}-show-text`]: !!tip, + [cls]: true, }; const spinElement = ( -
+
{this.renderIndicator(h, prefixCls)} {tip ?
{tip}
: null}
@@ -163,10 +155,7 @@ export default { }; return ( -
+
{sSpinning &&
{spinElement}
}
{children} diff --git a/package.json b/package.json index 70e07fb67..0063d007a 100644 --- a/package.json +++ b/package.json @@ -160,7 +160,6 @@ "vue-loader": "^16.0.0-beta.2", "vue-router": "^4.0.0-alpha.12", "vue-server-renderer": "^2.6.11", - "vue-template-compiler": "^2.6.11", "vue-virtual-scroller": "^1.0.0", "vuex": "^4.0.0-beta.2", "webpack": "^4.28.4",