Files
vue3-element-admin/src/components/Dictionary/index.vue
Jachin f797606c44 chore: prettier & lint
Former-commit-id: 486f65e137348f400d7b95067bd3cd5a2f23ff44
2023-08-07 18:39:29 +08:00

54 lines
1021 B
Vue

<template>
<div>
<el-select
v-model="selectedValue"
:placeholder="placeholder"
:disabled="disabled"
clearable
>
<el-option
v-for="option in options"
:key="option.value"
:label="option.label"
:value="option.value"
/>
</el-select>
</div>
</template>
<script setup lang="ts">
import { getDictOptions } from "@/api/dict";
const props = defineProps({
typeCode: {
type: String,
required: true,
},
modelValue: {
type: String,
default: "",
},
placeholder: {
type: String,
default: "请选择",
},
disabled: {
type: Boolean,
default: false,
},
});
const emits = defineEmits(["update:modelValue"]);
const selectedValue = useVModel(props, "modelValue", emits);
const options: Ref<OptionType[]> = ref([]);
onBeforeMount(() => {
// 根据字典类型编码(typeCode)获取字典选项
getDictOptions(props.typeCode).then((response) => {
options.value = response.data;
});
});
</script>