请教下,element-plus中怎么控制父级元素的隐藏?-灵析社区

接地气的编码师

我封装了element-plus中的form的组件,代码如下: // TagSelectItem.vue import { onMounted, ref } from "vue"; import { TagApi } from "@/api/project"; import { TagGroupApiProps } from "@/types/project"; const props = defineProps({ modelValue: { required: true, type: [Number, String, Array, Array] }, tagLists: { required: false, type: Array, default: [] }, multiple: { required: false, type: Boolean, default: true }, showLabel: { required: false, type: Boolean, default: true }, prop: { required: false, type: String, default: "tag_ids" }, maxCollapseTags: { required: false, type: Number, default: 7 } }); const emits = defineEmits(["update:modelValue", "click"]); const select = (value: number[]) => { emits("update:modelValue", value); emits("click", value); }; const lists = ref([]); onMounted(async () => { if (props.tagLists.length !== 0) { lists.value = props.tagLists; } else { lists.value = await TagApi.select(); } }); 使用组件: 默认是展示标签 通过show-label 隐藏 el-form-item 为了不显示 `el-form-item`,``的代码写了一遍,又复制了一遍。 请教下有没有啥好的办法,可以控制 `el-form-item` 的隐藏与展示,同时让``的代码只写一遍? 还有就是,组件这样写有没有不合理的地方。 欢迎指正,谢谢。

阅读量:17

点赞量:0

问AI
"image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20241129/88a998a4edfcc131efddcdc219e6687d.png) 是不是把这一块单独封装成组件 tag-select 然后这块封装成另一个组件 \---> 两个组件的使用场景不一致 tag-select-item 只会在el-form表单下才用 tag-select则可以在不同地方用 在不同场景用不同组件。 个人看法 楼主根据实际情况考虑