element基础详情页-文本描述组件

欢迎点击领取 -《前端开发面试题进阶秘籍》:前端登顶之巅-最全面的前端知识点梳理总结

*专享

最新版本element-ui 已支持详情描述组件,直接使用即可。
前言

对于常做topB系统的小伙伴们,基础信息详情页是最常见不过的。

在这里插入图片描述

使用

只是做了简易版,相关参数并不支持render的写法;有兴趣的可以写写,支持render后扩展性会更好

import DescriptionList from "./Description.vue"; // 引入组件

<DescriptionList title="退款申请" col="6" :content="data"> // col element-ui栅格栏布局同官网使用
  <Description term="取货单号">1000000000</Description> // 组件内使用固定标签
  <Description term="状态">已取货</Description>
  <Description term="销售单号">1234123421</Description>
  <Description term="子订单">3214321432</Description>
</DescriptionList>
组件
/** 
* 文本详情描述组件
*/
<template>
  <div class="description_text">
    <div v-if="title" class="title">{{title}}</div>
    <el-row :gutter="gutter">
      <el-col :key="key" :span="+col" v-for="(item, key) in dataSource">
        <div class="term">{{item.term}}</div>
        <div class="detail">{{item.detail}}</div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
const handleArrayObj = data => {
  return data
    .filter(item => item.tag === "Description")
    .map(item => ({
      tag: item.tag,
      term: (item.data && item.data.attrs.term) || "暂无",
      detail: (item.children && item.children[0].text) || "暂无"
    }));
};

export default {
  name: "Description",
  props: {
  	title: String,
  	content: [Object, Array],
    gutter: {
      type: [Number, String],
      default: 20
    },
    col: {
      type: [Number, String],
      default: 8
    }
  },

  data() {
    return {
      dataSource: handleArrayObj(this.$slots.default || [])
    };
  },
  watch: {
  	content() {
  		this.dataSource = handleArrayObj(this.$slots.default || []) 
  	} // 监听重渲染
};
</script>

<style lang="less" scoped>
.description_text {
  .title {
    font-weight: 700;
    font-size: 16px;
    line-height: 1.5;
    margin-bottom: 20px;
    color: rgba(0, 0, 0, 0.85);
  }
  .term {
    color: rgba(0,0,0,.85);
    font-weight: 400;
    font-size: 14px;
    line-height: 22px;
    padding-bottom: 16px;
    margin-right: 8px;
    white-space: nowrap;
    display: table-cell;
    &:after {
      content: ":";
      margin: 0 8px 0 2px;
      position: relative;
      top: -0.5px;
    }
  }
  .detail {
    font-size: 14px;
    line-height: 1.5;
    width: 100%;
    padding-bottom: 16px;
    color: rgba(0, 0, 0, 0.65);
    display: table-cell;
  }
}
</style>
  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SunnyRun!

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值