Skip to content

Commit

Permalink
refactor(DatetimePicker): refactor with composition api
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Sep 8, 2020
1 parent b17c67a commit 60e0876
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/datetime-picker/index.js
@@ -1,4 +1,6 @@
import { ref } from 'vue';
import { createNamespace } from '../utils';
import { usePublicApi } from '../composition/use-public-api';
import TimePicker from './TimePicker';
import DatePicker from './DatePicker';

Expand All @@ -10,15 +12,16 @@ export default createComponent({
...DatePicker.props,
},

methods: {
// @exposed-api
getPicker() {
return this.$refs.root.getPicker();
},
},
setup(props) {
const rootRef = ref();

usePublicApi({
getPicker: () => rootRef.value && rootRef.value.getPicker(),
});

render() {
const Component = this.type === 'time' ? TimePicker : DatePicker;
return <Component ref="root" class={bem()} {...this.$props} />;
return () => {
const Component = props.type === 'time' ? TimePicker : DatePicker;
return <Component ref={rootRef} class={bem()} {...props} />;
};
},
});

0 comments on commit 60e0876

Please sign in to comment.