0
0
Fork 0

perf: use ref at component start

This commit is contained in:
Javier Segarra 2024-07-23 20:18:53 +02:00
parent 1ac0a85969
commit e013e5571d
1 changed files with 34 additions and 7 deletions

View File

@ -28,7 +28,34 @@ const props = defineProps({
},
});
const categoryList = ref(null);
const selectedCategoryFk = ref(null);
const params = JSON.parse(route?.query?.params ?? '{}');
const filter = JSON.parse(params?.filter ?? '{}');
const selectedCategoryFk = ref(filter?.where?.categoryFk ?? null);
// CHATGPT
/**
// Función para parsear JSON de manera segura
const parseJSON = (str, fallback) => {
try {
return JSON.parse(str);
} catch (e) {
console.error("Error parsing JSON:", e);
return fallback;
}
};
// Obtener los parámetros de la ruta
const params = parseJSON(route?.query?.params, {});
// Extraer y parsear el filtro de los parámetros
const { filter: filterStr = '{}' } = params;
const filter = parseJSON(filterStr, {});
// Obtener el categoryFk del filtro, si existe
const selectedCategoryFk = ref(filter?.where?.categoryFk ?? null);
console.log(selectedCategoryFk.value);
*/
const typeList = ref([]);
const selectedTypeFk = ref(null);
const validationsStore = useValidator();
@ -178,13 +205,13 @@ const setCategoryList = (data) => {
}));
moreFields.value = useLang(_moreFields);
moreFieldsOrder.value = useLang(_moreFieldsTypes);
const { categoryFk } = JSON.parse(JSON.parse(route.query.params).filter).where;
// const { categoryFk } = JSON.parse(JSON.parse(route.query.params).filter).where;
if (!selectedCategoryFk.value) {
selectedCategoryFk.value = categoryFk;
selectedCategory.value = getCategory(categoryFk);
loadTypes(categoryFk);
}
// if (!selectedCategoryFk.value) {
// selectedCategoryFk.value = categoryFk;
// selectedCategory.value = getCategory(categoryFk);
// loadTypes(categoryFk);
// }
};
const getCategoryClass = (category, params) => {