perf(TextEllipsis): reuse windowWidth to avoid repeat calculations (#12471)

This commit is contained in:
inottn 2023-11-24 18:20:18 +08:00 committed by GitHub
parent 3410b1c74f
commit f0b7af18c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,11 +7,13 @@ import {
type ExtractPropTypes,
} from 'vue';
// Composables
import { useEventListener } from '@vant/use';
// Utils
import { makeNumericProp, makeStringProp, createNamespace } from '../utils';
import {
makeNumericProp,
makeStringProp,
createNamespace,
windowWidth,
} from '../utils';
const [name, bem] = createNamespace('text-ellipsis');
@ -196,9 +198,10 @@ export default defineComponent({
onMounted(calcEllipsised);
watch(() => [props.content, props.rows, props.position], calcEllipsised);
useEventListener('resize', calcEllipsised);
watch(
[windowWidth, () => [props.content, props.rows, props.position]],
calcEllipsised,
);
return () => (
<div ref={root} class={bem()}>