Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | <template> <component :is="is" v-bind="passthroughAttrs" :model-value="resolvedModelValue" @update:model-value="resolvedUpdater" > <template #label> <div class="inline-flex items-center gap-1"> <span class="mr-3">{{ baseLabel }}</span> <v-chip v-if="required" color="error" label size="x-small" class="text-white"> {{ t('ui.form.required') }} </v-chip> <v-chip v-else color="grey" label size="x-small" variant="outlined"> {{ t('ui.form.optional') }} </v-chip> </div> </template> <slot></slot> </component> </template> <script setup lang="ts"> // region import import { computed, useAttrs } from 'vue' import { useI18n } from 'vue-i18n' // endregion import // region Component defineOptions({ name: 'BaseRequiredField' }) // endregion Component // region types // endregion types // region interface // endregion interface // region props const props = withDefaults(defineProps<{ modelValue?: any is: 'v-text-field' | 'v-select' | 'v-textarea' labelKey?: string label?: string required?: boolean }>(), { modelValue: null, required: false, }) // endregion props // region emits const emit = defineEmits<{ (e: 'update:modelValue', v: any): void }>() // endregion emits // region expose // endregion expose // region slots // endregion slots // region i18n const { t } = useI18n() // endregion i18n // region router // endregion router // region store // endregion store // region consts const rawAttrs = useAttrs() as Record<string, unknown> // endregion consts // region state // endregion state // region computed const baseLabel = computed(() => props.labelKey ? t(props.labelKey) : (props.label ?? '') ) /** v-bind(field) 優先で modelValue / updater を解決 */ const resolvedModelValue = computed(() => rawAttrs.modelValue !== undefined ? rawAttrs.modelValue : props.modelValue ) const resolvedUpdater = (v: any) => { const updater = rawAttrs['onUpdate:modelValue'] as ((v: any) => void) | undefined if (updater) return updater(v) emit('update:modelValue', v) } /** 二重渡し防止のため、modelValue 関連は attrs から取り除いて透過 */ const passthroughAttrs = computed(() => { const { modelValue, ['onUpdate:modelValue']: _omit, ...rest } = rawAttrs return rest }) // endregion computed // region validation // endregion validation // region watchers // endregion watchers // region effects // endregion effects // region permissions // endregion permissions // region api // endregion api // region handlers // endregion handlers // region lifecycle // endregion lifecycle // region provide // endregion provide // region inject // endregion inject // region expose-public // endregion expose-public // region devtools // endregion devtools // region test-ids // endregion test-ids // region variable // endregion variable // region properties // endregion properties // region methods // endregion methods // region export // endregion export </script> <style scoped> </style> |