vue3+element-plus el-descriptions 详情组件二次封装(vue3项目)
    		       		warning:
    		            这篇文章距离上次修改已过439天,其中的内容可能已经有所变动。
    		        
        		                
                
<template>
  <el-descriptions
    :title="title"
    :border="border"
    :column="column"
    :size="size"
    :label-style="labelStyle"
    :content-style="contentStyle"
  >
    <template v-for="(item, index) in list" :key="index" #[item.slotName]>
      <span v-html="item.value"></span>
    </template>
    <template #extra>
      <slot name="extra"></slot>
    </template>
  </el-descriptions>
</template>
 
<script setup lang="ts">
import { PropType } from 'vue';
import type { DescriptionsItem } from 'element-plus';
 
defineProps({
  title: String,
  border: Boolean,
  column: {
    type: Number as PropType<1 | 2>,
    default: 1,
  },
  size: {
    type: String as PropType<'default' | 'large'>,
    default: 'default',
  },
  labelStyle: {
    type: Object as PropType<CSSStyleDeclaration>,
    default: () => ({}),
  },
  contentStyle: {
    type: Object as PropType<CSSStyleDeclaration>,
    default: () => ({}),
  },
  list: {
    type: Array as PropType<DescriptionsItem[]>,
    default: () => [],
  },
});
</script>这个示例展示了如何在Vue 3项目中使用Vue的 <script setup> 语法和TypeScript来封装一个基于 Element Plus 的 el-descriptions 组件。组件接受不同的属性,并通过v-html指令来渲染列表中定义的HTML内容。此外,它还提供了一个名为"extra"的插槽用于添加额外的信息。
评论已关闭