mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-09-01 13:49:45 +08:00
types: improve ref typing (#8124)
* types: improve ref typing * types: message
This commit is contained in:
parent
3e08b2471a
commit
0b68d3a141
@ -1,8 +1,8 @@
|
|||||||
import { useRect } from '@vant/use';
|
import { useRect } from '@vant/use';
|
||||||
import { Ref, ref, onMounted, nextTick } from 'vue';
|
import { Ref, ref, onMounted, nextTick } from 'vue';
|
||||||
|
|
||||||
export const useHeight = (element: Element | Ref<Element>) => {
|
export const useHeight = (element: Element | Ref<Element | undefined>) => {
|
||||||
const height = ref();
|
const height = ref<number>();
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
|
@ -2,7 +2,7 @@ import { useHeight } from './use-height';
|
|||||||
import type { Ref } from 'vue';
|
import type { Ref } from 'vue';
|
||||||
import type { BEM } from '../utils/create/bem';
|
import type { BEM } from '../utils/create/bem';
|
||||||
|
|
||||||
export function usePlaceholder(contentRef: Ref<Element>, bem: BEM) {
|
export function usePlaceholder(contentRef: Ref<Element | undefined>, bem: BEM) {
|
||||||
const height = useHeight(contentRef);
|
const height = useHeight(contentRef);
|
||||||
|
|
||||||
return (renderContent: () => JSX.Element) => (
|
return (renderContent: () => JSX.Element) => (
|
||||||
|
@ -31,7 +31,7 @@ export default createComponent({
|
|||||||
emits: ['click-left', 'click-right'],
|
emits: ['click-left', 'click-right'],
|
||||||
|
|
||||||
setup(props, { emit, slots }) {
|
setup(props, { emit, slots }) {
|
||||||
const navBarRef = ref();
|
const navBarRef = ref<HTMLElement>();
|
||||||
const renderPlaceholder = usePlaceholder(navBarRef, bem);
|
const renderPlaceholder = usePlaceholder(navBarRef, bem);
|
||||||
|
|
||||||
const onClickLeft = (event: MouseEvent) => {
|
const onClickLeft = (event: MouseEvent) => {
|
||||||
|
@ -46,8 +46,8 @@ export default createComponent({
|
|||||||
let contentWidth = 0;
|
let contentWidth = 0;
|
||||||
let startTimer: NodeJS.Timeout;
|
let startTimer: NodeJS.Timeout;
|
||||||
|
|
||||||
const wrapRef = ref();
|
const wrapRef = ref<HTMLElement>();
|
||||||
const contentRef = ref();
|
const contentRef = ref<HTMLElement>();
|
||||||
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
show: true,
|
show: true,
|
||||||
|
@ -112,7 +112,7 @@ export default createComponent({
|
|||||||
let shouldReopen: boolean;
|
let shouldReopen: boolean;
|
||||||
|
|
||||||
const zIndex = ref<number>();
|
const zIndex = ref<number>();
|
||||||
const popupRef = ref();
|
const popupRef = ref<HTMLElement>();
|
||||||
|
|
||||||
const [lockScroll, unlockScroll] = useLockScroll(
|
const [lockScroll, unlockScroll] = useLockScroll(
|
||||||
popupRef,
|
popupRef,
|
||||||
|
@ -52,7 +52,7 @@ export default createComponent({
|
|||||||
setup(props, { emit, slots }) {
|
setup(props, { emit, slots }) {
|
||||||
let reachTop: boolean;
|
let reachTop: boolean;
|
||||||
|
|
||||||
const root = ref();
|
const root = ref<HTMLElement>();
|
||||||
const scrollParent = useScrollParent(root);
|
const scrollParent = useScrollParent(root);
|
||||||
|
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
|
@ -127,7 +127,7 @@ export default createComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
let actionType: 'plus' | 'minus';
|
let actionType: 'plus' | 'minus';
|
||||||
const inputRef = ref();
|
const inputRef = ref<HTMLInputElement>();
|
||||||
const current = ref(getInitialValue());
|
const current = ref(getInitialValue());
|
||||||
|
|
||||||
const minusDisabled = computed(
|
const minusDisabled = computed(
|
||||||
|
@ -65,7 +65,7 @@ function parseOptions(message: string | ToastOptions): ToastOptions {
|
|||||||
function createInstance() {
|
function createInstance() {
|
||||||
const { instance, unmount } = mountComponent({
|
const { instance, unmount } = mountComponent({
|
||||||
setup() {
|
setup() {
|
||||||
const message = ref();
|
const message = ref('');
|
||||||
const { open, state, close, toggle } = usePopupState();
|
const { open, state, close, toggle } = usePopupState();
|
||||||
|
|
||||||
const onClosed = () => {
|
const onClosed = () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user