birdpaper-ui
Version:
一个通用的 vue3 UI组件库。A common vue3 UI component library.
46 lines (45 loc) • 1.11 kB
JavaScript
import { defineComponent, ref, watch } from "vue";
import Radio from "../../../radio/index.js";
import Checkbox from "../../../checkbox/index.js";
const _sfc_main = defineComponent({
name: "TableSelect",
props: {
/** 已选择数据绑定值 */
modelValue: { type: Array, default: () => [] },
/** 选择器类型 */
type: { type: String, default: "radio" },
/** 数据记录 */
record: { type: Object },
/** 数据 key 值 */
value: { type: [String, Number] }
},
emits: ["update:modelValue", "change"],
setup(props, { emit }) {
const selectionType = {
radio: Radio,
checkbox: Checkbox
};
const selectValue = ref([]);
const onSelectChange = () => {
emit("update:modelValue", selectValue.value);
setTimeout(() => {
emit("change", props.record);
}, 20);
};
watch(
() => props.modelValue,
(v) => {
selectValue.value = v;
},
{ immediate: true }
);
return {
selectValue,
onSelectChange,
selectionType
};
}
});
export {
_sfc_main as default
};