mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-24 10:20:19 +08:00
perf: reduce ref call
This commit is contained in:
parent
a00e6f3474
commit
04290db467
@ -1,4 +1,4 @@
|
|||||||
import { ref, computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
import { createNamespace } from '../utils';
|
import { createNamespace } from '../utils';
|
||||||
import { route, routeProps } from '../utils/router';
|
import { route, routeProps } from '../utils/router';
|
||||||
import { useParent } from '../api/use-relation';
|
import { useParent } from '../api/use-relation';
|
||||||
@ -19,13 +19,13 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
setup(props, { slots }) {
|
setup(props, { slots }) {
|
||||||
const { parent, index } = useParent(ACTION_BAR_KEY, ref(true));
|
const { parent, index } = useParent(ACTION_BAR_KEY, { isButton: true });
|
||||||
|
|
||||||
const isFirst = computed(() => {
|
const isFirst = computed(() => {
|
||||||
if (parent) {
|
if (parent) {
|
||||||
const children = parent.children.value;
|
const children = parent.children.value;
|
||||||
const prev = children[index.value - 1];
|
const prev = children[index.value - 1];
|
||||||
return !(prev && prev.value);
|
return !(prev && prev.isButton);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ export default createComponent({
|
|||||||
if (parent) {
|
if (parent) {
|
||||||
const children = parent.children.value;
|
const children = parent.children.value;
|
||||||
const next = children[index.value + 1];
|
const next = children[index.value + 1];
|
||||||
return !(next && next.value);
|
return !(next && next.isButton);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
import { ref, Ref, inject, computed, onUnmounted } from 'vue';
|
import { Ref, inject, computed, onUnmounted } from 'vue';
|
||||||
|
|
||||||
export type Parent<T = unknown> = null | {
|
export type Parent<T = unknown> = null | {
|
||||||
children: Ref<Ref<T>[]>;
|
children: Ref<T[]>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useParent<T = unknown>(
|
export function useParent<T = unknown>(key: string, child: T = {} as T) {
|
||||||
key: string,
|
|
||||||
child: Ref<T> = ref() as Ref<T>
|
|
||||||
) {
|
|
||||||
const parent = inject<Parent<T>>(key, null);
|
const parent = inject<Parent<T>>(key, null);
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user