mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-23 18:00:27 +08:00
feat: add useRect
This commit is contained in:
parent
b12fdad916
commit
216d326158
7
src/api/use-rect.ts
Normal file
7
src/api/use-rect.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import type { Ref } from 'vue';
|
||||||
|
|
||||||
|
export const useRect = (el: Ref<Element>) => el.value.getBoundingClientRect();
|
||||||
|
|
||||||
|
export const useWidth = (el: Ref<Element>) => useRect(el).width;
|
||||||
|
|
||||||
|
export const useHeight = (el: Ref<Element>) => useRect(el).height;
|
@ -1,7 +1,10 @@
|
|||||||
import { ref, computed, getCurrentInstance } from 'vue';
|
import { ref, computed, getCurrentInstance } from 'vue';
|
||||||
|
|
||||||
|
// Utils
|
||||||
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';
|
||||||
|
import { getMonthEndDay } from '../../datetime-picker/utils';
|
||||||
import {
|
import {
|
||||||
t,
|
t,
|
||||||
bem,
|
bem,
|
||||||
@ -11,8 +14,12 @@ import {
|
|||||||
getNextDay,
|
getNextDay,
|
||||||
formatMonthTitle,
|
formatMonthTitle,
|
||||||
} from '../utils';
|
} from '../utils';
|
||||||
|
|
||||||
|
// Compositions
|
||||||
|
import { useHeight } from '../../api/use-rect';
|
||||||
import { useToggle } from '../../api/use-toggle';
|
import { useToggle } from '../../api/use-toggle';
|
||||||
import { getMonthEndDay } from '../../datetime-picker/utils';
|
|
||||||
|
// Components
|
||||||
import Day from './Day';
|
import Day from './Day';
|
||||||
|
|
||||||
const [createComponent] = createNamespace('calendar-month');
|
const [createComponent] = createNamespace('calendar-month');
|
||||||
@ -78,7 +85,7 @@ export default createComponent({
|
|||||||
let height;
|
let height;
|
||||||
const getHeight = () => {
|
const getHeight = () => {
|
||||||
if (!height) {
|
if (!height) {
|
||||||
({ height } = monthRef.value.getBoundingClientRect());
|
height = useHeight(monthRef);
|
||||||
}
|
}
|
||||||
return height;
|
return height;
|
||||||
};
|
};
|
||||||
|
@ -4,6 +4,9 @@ import { ref, onMounted } from 'vue';
|
|||||||
import { createNamespace } from '../utils';
|
import { createNamespace } from '../utils';
|
||||||
import { BORDER_BOTTOM } from '../utils/constant';
|
import { BORDER_BOTTOM } from '../utils/constant';
|
||||||
|
|
||||||
|
// Compositions
|
||||||
|
import { useHeight } from '../api/use-rect';
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
import Icon from '../icon';
|
import Icon from '../icon';
|
||||||
|
|
||||||
@ -32,7 +35,7 @@ export default createComponent({
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (props.placeholder && props.fixed) {
|
if (props.placeholder && props.fixed) {
|
||||||
height.value = navBarRef.value.getBoundingClientRect().height;
|
height.value = useHeight(navBarRef);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user