chore: improve exposed api

This commit is contained in:
chenjiahan 2020-08-26 11:14:36 +08:00
parent 762aed3e5d
commit d0848544d4
3 changed files with 39 additions and 30 deletions

View File

@ -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 { createNamespace, pick } from '../utils';
import { pickerProps } from '../picker/shared'; import { pickerProps } from '../picker/shared';
import Picker from '../picker'; import Picker from '../picker';
@ -273,11 +281,12 @@ export default createComponent({
} }
); );
return (vm) => { // @exposed-api
// @exposed-api const vm = getCurrentInstance().proxy;
vm.reset = reset; vm.reset = reset;
vm.getArea = getArea; vm.getArea = getArea;
return () => {
const columns = state.columns.slice(0, +props.columnsNum); const columns = state.columns.slice(0, +props.columnsNum);
return ( return (

View File

@ -1,4 +1,4 @@
import { ref, computed } from 'vue'; import { ref, computed, getCurrentInstance } from 'vue';
import { createNamespace, addUnit } from '../../utils'; import { createNamespace, addUnit } from '../../utils';
import { unitToPx } from '../../utils/format/unit'; import { unitToPx } from '../../utils/format/unit';
import { setScrollTop } from '../../utils/dom/scroll'; import { setScrollTop } from '../../utils/dom/scroll';
@ -246,19 +246,19 @@ export default createComponent({
return <div ref={daysRef} />; return <div ref={daysRef} />;
}; };
return (vm) => { // @exposed-api
vm.getDate = getDate; const vm = getCurrentInstance().proxy;
vm.getTitle = getTitle; vm.getDate = getDate;
vm.getHeight = getHeight; vm.getTitle = getTitle;
vm.setVisible = setVisible; vm.getHeight = getHeight;
vm.scrollIntoView = scrollIntoView; vm.setVisible = setVisible;
vm.scrollIntoView = scrollIntoView;
return ( return () => (
<div class={bem('month')} ref={monthRef} style={monthStyle.value}> <div class={bem('month')} ref={monthRef} style={monthStyle.value}>
{renderTitle()} {renderTitle()}
{renderDays()} {renderDays()}
</div> </div>
); );
};
}, },
}); });

View File

@ -5,6 +5,7 @@ import {
onActivated, onActivated,
onDeactivated, onDeactivated,
onBeforeUnmount, onBeforeUnmount,
getCurrentInstance,
} from 'vue'; } from 'vue';
import { createNamespace } from '../utils'; import { createNamespace } from '../utils';
import { raf, cancelRaf } from '../utils/dom/raf'; import { raf, cancelRaf } from '../utils/dom/raf';
@ -135,17 +136,16 @@ export default createComponent({
onBeforeUnmount(pause); onBeforeUnmount(pause);
return (vm) => { // @exposed-api
// @exposed-api const vm = getCurrentInstance().proxy;
vm.start = start; vm.start = start;
vm.reset = reset; vm.reset = reset;
vm.pause = pause; vm.pause = pause;
return ( return () => (
<div class={bem()}> <div class={bem()}>
{slots.default ? slots.default(timeData.value) : timeText.value} {slots.default ? slots.default(timeData.value) : timeText.value}
</div> </div>
); );
};
}, },
}); });