useAttrs
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Alex Moreno 2024-07-12 14:13:35 +02:00
parent b30da92c1d
commit bfab1ec314
1 changed files with 5 additions and 10 deletions

View File

@ -1,7 +1,6 @@
<script setup> <script setup>
import { ref, onBeforeMount } from 'vue'; import { ref, onBeforeMount, useAttrs } from 'vue';
import VnSelect from 'src/components/common/VnSelect.vue'; import VnSelect from 'src/components/common/VnSelect.vue';
import { useArrayData } from 'src/composables/useArrayData';
const $props = defineProps({ const $props = defineProps({
row: { row: {
@ -12,19 +11,15 @@ const $props = defineProps({
type: String, type: String,
default: null, default: null,
}, },
url: {
type: String,
default: '',
},
}); });
const options = ref([]); const options = ref([]);
onBeforeMount(async () => { onBeforeMount(async () => {
const findBy = const { url } = useAttrs();
$props.find ?? $props.url.charAt(0).toLocaleLowerCase() + $props.url.slice(1, -1); const findBy = $props.find ?? url?.charAt(0)?.toLocaleLowerCase() + url?.slice(1, -1);
options.value = [$props.row[findBy]]; if (findBy) options.value = [$props.row[findBy]];
}); });
</script> </script>
<template> <template>
<VnSelect v-bind="$attrs" :options="$attrs.options ?? options" :url="url" /> <VnSelect v-bind="$attrs" :options="$attrs.options ?? options" />
</template> </template>