vue antv 自定义Descriptions 描述列表

思路:根据具体内容进行数据data中list的结构修改,再在template进行判断、展示

新增了slot

【template】

<template>
<div>
  <a-descriptions :column="2" bordered>
    <a-descriptions-item v-for="item in list" :key="item.id" :label="item.label" :span="item.colSpan">
      <template v-if="item.type == 'text'">
        <div class="flex">
          <div>{{ item.text }}</div>
        </div>
      </template>
      <a-button v-if="item.type == 'link'" type="link">{{ item.text}}</a-button>
      <template v-if="item.type == 'copy'">
        <div class="flex">
          <div>{{ item.text }}</div>
          <a-icon type="copy" title="copy" />
        </div>
      </template>
      <template v-if="item.type == 'textList'">
        <div class="flex" v-for="val in item.textList" :key="val.txt">
          <div v-for="(txt, key, keyindex) in val" :key="keyindex">
            {{ txt }} <span v-if="keyindex != Object.keys(val).length-1 ">|</span>
          </div>
        </div>
      </template>
      <template v-if="item.type == 'linkList'">
        <div class="flex" v-for="val in item.linkList" :key="val.txt.name">
          <div>{{ val.txt.name }} |
            <a-button type="link">{{ val.txt.val }}</a-button>
          </div>
          <div class="flex">
            <div v-for="(icon,index) in val.icons" :key="icon">
              <a-icon :type="icon"/>
              <span v-if="index != val.icons.length -1 ">|</span>
            </div>
          </div>
        </div>
      </template>
        <div v-if="item.type == 'slot'">
            <slot :name="item.slotNmae">
        
            </slot>
        </div>
    </a-descriptions-item>
  </a-descriptions>
</div>
</template>

【data】

 data() {
    return {
      list: [
        {
          id: "100000001",
          colSpan: 1,
          label: "Text",
          type: "text", // text link copy textList linkList
          text: 'text',
        },
        {
          id: "100000002",
          colSpan: 1,
          label: "Link",
          type: "link", // text link copy textList linkList
          text: 'link',
        },
        {
          id: "100000003",
          colSpan: 1,
          label: "copy",
          type: "copy", // text link copy textList linkList
          text: 'copy',
        },     
        {
          id: "1000000012",
          colSpan: 1,
          label: "linkList",
          type: "linkList", // text link copy textList linkList
          linkList: [
            {
              txt: {
                name: "linkList01",
                val: "my link 01"
              },
              icons: ["wechat", "qq"]
            },
            {
              txt: {
                name: "linkList02",
                val: "my link 02"
              },
              icons: ["qq"]
            },
          ],
        },
        {
          id: "1000000014",
          colSpan: 2,
          label: "textList",
          type: "textList", // text link copy textList linkList
          textList: [
            {
              name: "name",
              value: "value"
            },
            {
              name: "name",
              value: "value",
              type: "type"
            },
          ],
        },
        {
          id: "1000000015",
          colSpan: 2,
          label: "des",
          type: "text", // text link copy textList linkList
          text: 'des',
        },
        {
          id: "1000000016",
          colSpan: 1,
          label: "Desc",
          type: "slot", // text link copy textList linkList
          slotNmae: "desc",
        },
      ]

    }
  },

【slot使用】

<CusDescOperate :list="list">
    <div slot="desc">
        <a-button>Setting</a-button>
    </div>
</CusDescOperate>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值