types: improve ref typing (#8124)

* types: improve ref typing

* types: message
This commit is contained in:
neverland 2021-02-10 20:57:24 +08:00 committed by GitHub
parent 3e08b2471a
commit 0b68d3a141
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 10 additions and 10 deletions

View File

@ -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(() => {

View File

@ -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) => (

View File

@ -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) => {

View File

@ -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,

View File

@ -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,

View File

@ -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({

View File

@ -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(

View File

@ -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 = () => {