From d0848544d4ad38981ee0fafdbbd3c16c11d30f50 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Wed, 26 Aug 2020 11:14:36 +0800 Subject: [PATCH] chore: improve exposed api --- src/area/index.js | 19 ++++++++++++++----- src/calendar/components/Month.js | 28 ++++++++++++++-------------- src/count-down/index.js | 22 +++++++++++----------- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/area/index.js b/src/area/index.js index a6bb4c978..60ec8ec2c 100644 --- a/src/area/index.js +++ b/src/area/index.js @@ -1,4 +1,12 @@ -import { ref, watch, computed, reactive, nextTick, onMounted } from 'vue'; +import { + ref, + watch, + computed, + reactive, + nextTick, + onMounted, + getCurrentInstance, +} from 'vue'; import { createNamespace, pick } from '../utils'; import { pickerProps } from '../picker/shared'; import Picker from '../picker'; @@ -273,11 +281,12 @@ export default createComponent({ } ); - return (vm) => { - // @exposed-api - vm.reset = reset; - vm.getArea = getArea; + // @exposed-api + const vm = getCurrentInstance().proxy; + vm.reset = reset; + vm.getArea = getArea; + return () => { const columns = state.columns.slice(0, +props.columnsNum); return ( diff --git a/src/calendar/components/Month.js b/src/calendar/components/Month.js index 5bd6591d0..24d47f979 100644 --- a/src/calendar/components/Month.js +++ b/src/calendar/components/Month.js @@ -1,4 +1,4 @@ -import { ref, computed } from 'vue'; +import { ref, computed, getCurrentInstance } from 'vue'; import { createNamespace, addUnit } from '../../utils'; import { unitToPx } from '../../utils/format/unit'; import { setScrollTop } from '../../utils/dom/scroll'; @@ -246,19 +246,19 @@ export default createComponent({ return
; }; - return (vm) => { - vm.getDate = getDate; - vm.getTitle = getTitle; - vm.getHeight = getHeight; - vm.setVisible = setVisible; - vm.scrollIntoView = scrollIntoView; + // @exposed-api + const vm = getCurrentInstance().proxy; + vm.getDate = getDate; + vm.getTitle = getTitle; + vm.getHeight = getHeight; + vm.setVisible = setVisible; + vm.scrollIntoView = scrollIntoView; - return ( -
- {renderTitle()} - {renderDays()} -
- ); - }; + return () => ( +
+ {renderTitle()} + {renderDays()} +
+ ); }, }); diff --git a/src/count-down/index.js b/src/count-down/index.js index fcd06a18e..2e79f4971 100644 --- a/src/count-down/index.js +++ b/src/count-down/index.js @@ -5,6 +5,7 @@ import { onActivated, onDeactivated, onBeforeUnmount, + getCurrentInstance, } from 'vue'; import { createNamespace } from '../utils'; import { raf, cancelRaf } from '../utils/dom/raf'; @@ -135,17 +136,16 @@ export default createComponent({ onBeforeUnmount(pause); - return (vm) => { - // @exposed-api - vm.start = start; - vm.reset = reset; - vm.pause = pause; + // @exposed-api + const vm = getCurrentInstance().proxy; + vm.start = start; + vm.reset = reset; + vm.pause = pause; - return ( -
- {slots.default ? slots.default(timeData.value) : timeText.value} -
- ); - }; + return () => ( +
+ {slots.default ? slots.default(timeData.value) : timeText.value} +
+ ); }, });