vxe-pc-ui
Version:
A vue based PC component library
41 lines (40 loc) • 1.27 kB
JavaScript
import { defineComponent, h, onUnmounted, provide, inject, ref, onMounted } from 'vue';
import { createOption, watchOption, destroyOption, assembleOption } from './util';
export default defineComponent({
name: 'VxeOptgroup',
props: {
label: {
type: [String, Number, Boolean],
default: ''
},
visible: {
type: Boolean,
default: null
},
className: [String, Function],
disabled: Boolean
},
emits: [],
setup(props, { slots }) {
const elem = ref();
const $xeSelect = inject('$xeSelect', {});
const optionConfig = createOption($xeSelect, props);
const $xeOptgroup = { optionConfig };
optionConfig.options = [];
provide('$xeOptgroup', $xeOptgroup);
watchOption(props, optionConfig);
onMounted(() => {
const el = elem.value;
assembleOption($xeSelect, el, optionConfig);
});
onUnmounted(() => {
destroyOption($xeSelect, optionConfig);
});
return () => {
const defaultSlot = slots.default;
return h('div', {
ref: elem
}, defaultSlot ? defaultSlot({}) : []);
};
}
});