自定义 Select 选择器
- 父组件
import lcaPanel from '@/components/lcaPanel.vue'
<template>
<selectRole v-model:value="roleCode" @call="onCall" />
</template>
<style lang="less" scoped></style>
<script setup>
import {ref} from "vue";
import selectRole from '@/components/selectRole.vue'
const roleCode = ref('0')
const onCall = () => {
console.log('选中的值为',roleCode)
}
</script>
<template>
<a-select
:value="modelValue"
show-search
placeholder="Select a person"
@change="handleChange"
>
<a-select-option
v-for="item in options"
:key="item.roleCode"
:value="item.roleCode"
>
{{ item.roleName }}({{ item.roleCode }})
</a-select-option>
</a-select>
</template>
<style lang="less" scoped>
</style>
<script setup>
import { ref, onMounted } from "vue";
import rbacApi from "@/api/rbacApi.js";
const options = ref([]);
const props = defineProps({
modelValue: {
type: String,
default: "",
},
});
const emit = defineEmits(["update:modelValue", 'call']);
const handleChange = (value) => {
emit("update:modelValue", value);
emit("call");
};
onMounted(() => {
getAllFn();
});
const getAllFn = () => {
rbacApi.getAll().then((res) => {
if (res.resultCode == "SUCCESS") {
options.value = res.data || [];
}
});
};
</script>