From 88e5dd08b8cf92f5b224d9b805365dd1407b4d1c Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 13 Sep 2024 11:18:46 +0200 Subject: [PATCH] perf: use $props.params --- src/components/common/VnSelect.vue | 33 ++---------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/src/components/common/VnSelect.vue b/src/components/common/VnSelect.vue index e3a5544f2..3b54e43ef 100644 --- a/src/components/common/VnSelect.vue +++ b/src/components/common/VnSelect.vue @@ -3,7 +3,6 @@ import { ref, toRefs, computed, watch, onMounted } from 'vue'; import { useI18n } from 'vue-i18n'; import { useArrayData } from 'src/composables/useArrayData'; import { useAttrs } from 'vue'; -import FetchData from 'components/FetchData.vue'; const emit = defineEmits(['update:modelValue', 'update:options', 'remove']); const $props = defineProps({ @@ -111,34 +110,17 @@ const selectValue = computed({ return $props.modelValue; }, set(value) { - // arrayData.store.page = 0; - // arrayData.store.hasMoreData = true; setOptions(myOptionsOriginal.value); emit('update:modelValue', value); }, }); -// watch(options, (newValue) => { -// setOptions(newValue); -// }); - -// watch(modelValue, (newValue) => { -// if (!myOptions.value.some((option) => option[optionValue.value] == newValue)) -// fetchFilter(newValue); -// }); - -// onMounted(() => { -// setOptions(options.value); -// if (useURL.value && $props.modelValue && !findKeyInOptions()) -// fetchFilter($props.modelValue); -// if ($props.focusOnMount) setTimeout(() => vnSelectRef.value.showPopup(), 300); -// }); - const $attrs = useAttrs(); const arrayDataKey = $props.dataKey ?? (useURL.value?.length > 0 ? useURL.value : $attrs.label); const arrayData = useArrayData(arrayDataKey, { url: useURL.value }); +const getVal = (val) => ($props.useLike ? { like: `%${val}%` } : val); watch(modelValue, (newValue) => { if (!myOptions.value.some((option) => option[optionValue.value] == newValue)) @@ -204,6 +186,7 @@ async function fetchFilter(val) { const where = { ...(val ? defaultWhere : {}), ...$props.where }; const fetchOptions = { where, order: sortBy, include, limit }; if (fields) fetchOptions.fields = fields; + arrayData.store.userParams = $props.params; arrayData.store.userFilter = fetchOptions; arrayData.store.order = fetchOptions.order; arrayData.store.skip = 0; @@ -258,21 +241,9 @@ async function onScroll({ to, direction, from, index }) { function nullishToTrue(value) { return value ?? true; } - -const getVal = (val) => ($props.useLike ? { like: `%${val}%` } : val);