Element UI中 自定义环形el-progress 更改背景、添加内外边框等

先看效果图:

Element UI 官网示例:
在这里插入图片描述
更改后效果:

在这里插入图片描述
引入el- progress

                <el-progress
                    type="circle"
                    class="load-factor"
                    :width="70"
                    :stroke-width="10"
                    :color="circolor"   //通过配置该color,来设置进度条的颜色,此次的渐变色就是通过color实现的
                    :percentage="50"
                    :format="format"
                ></el-progress>

该color中为strike属性,直接按照普通渐变色设置无效
因此:

				<svg>
                    <defs>
                        <linearGradient id="colors" x1="0%" y1="100%" x2="100%" y2="0%">
                            <stop offset="0%" style="stop-color:#E5F1FF" stop-opacity="0.8"></stop>
                            <stop offset="100%" style="stop-color:#567FFF" stop-opacity="1"></stop>
                        </linearGradient>
                    </defs>
                </svg>
    mounted() {
        this.circolor = 'url(#colors)'
    },

通过以上步骤可直接实现进度条渐变色,接下来为背景内外边框的设置
在element中没有该属性,因此决定曲线救国

        <div class="peak-load-ratio">
            <div
                class="peak-load"
                :class="{ active: current == item.id }"
                v-for="(item, index) in peakLoadData"
                :key="index"
                @click="peakLoadHandle(item, index)"
            >
                <el-progress
                    type="circle"
                    class="load-factor"
                    :width="70"
                    :stroke-width="10"
                    :color="circolor"
                    :percentage="50"
                    :format="format"
                ></el-progress>
                <p class="cir-status">充电中</p>
                <p class="cir-number">254</p>
                <div class="set-in-cir"></div>
                <svg>
                    <defs>
                        <linearGradient id="colors" x1="0%" y1="100%" x2="100%" y2="0%">
                            <stop offset="0%" style="stop-color:#E5F1FF" stop-opacity="0.8"></stop>
                            <stop offset="100%" style="stop-color:#567FFF" stop-opacity="1"></stop>
                        </linearGradient>
                    </defs>
                </svg>
            </div>
        </div>

CSS

    .peak-load-ratio {
        position: absolute;
        // top: 250px;
        // margin: 10px 20px;
        bottom: 20px;
        margin: 0 29px 10px;
        .title-text {
            // margin-bottom: 18px;
            font-weight: 700;
        }
        .set-in-cir {   //设置的内边框
            width: 42px;
            height: 42px;
            border: 1px solid #bfdcff;
            position: absolute;
            border-radius: 50%;
            margin-left: 15px;
            top: 15px;
            background: radial-gradient(at center, #ffffff 50%, #bcdbff 100%);
            opacity: 0.5;
        }
        .peak-load {
            // display: inline-block;
            float: left;
            width: 80px;
            margin-right: 5px;
            height: 112px;
            cursor: pointer;
            .load-factor {
                width: 72px;
                height: 72px;
                border: 1px dashed #c4c1c1;  //设置的外边框
                border-radius: 50%;
                /deep/ .el-progress-circle {
                    padding: 1px;
                }
                /deep/ .el-progress--circle .el-progress__text {
                    left: 5px;
                }
            }
            .cir-status {
                font-family: PingFangSC-Regular;
                font-size: 12px;
                color: #333333;
                letter-spacing: 0.29px;
                text-align: center;
                margin: 5px 0;
            }
            .cir-number {
                font-family: PingFangSC-Semibold;
                font-size: 16px;
                color: #333333;
                text-align: center;
                font-weight: bolder;
            }
            // p {
            //     width: 88px;
            //     // height: 18px;
            //     text-align: center;
            // }
        }
        // .active {
        //     // opacity: 0.6;
        //     background: rgba(24, 144, 255, 0.11);
        //     border-radius: 4px;
        // }
    }

修改其背景颜色:

/* .el-progress-circle__track {
    stroke: #ffffff;
} */

到这,基本上问题都解决了,完美完成需求。

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
您好,关于 element-ui 的上传组件 el-upload,您可以通过自定义 el-upload-list 来实现自定义上传列表的功能。 具体实现方法如下: 1. 在 el-upload 组件添加属性 list-type="picture-card",并设置属性 action 为上传文件的地址。 2. 在 el-upload 组件添加自定义 slot,用于自定义上传列表的显示。 3. 在自定义的上传列表组件,使用 el-upload-list 组件来展示上传文件的列表。 4. 可以通过监听 el-upload 组件的 change 事件来获取上传的文件信息,并将上传的文件信息传递给自定义的上传列表组件,以展示上传文件的列表。 以下是一个简单的示例代码: ```html <template> <div> <el-upload class="upload-demo" action="/upload" list-type="picture-card" :on-change="handleChange" > <i class="el-icon-plus"></i> <div class="upload-text">上传图片</div> </el-upload> <custom-upload-list :file-list="fileList"></custom-upload-list> </div> </template> <script> import CustomUploadList from './CustomUploadList.vue'; export default { components: { CustomUploadList, }, data() { return { fileList: [], }; }, methods: { handleChange(file, fileList) { this.fileList = fileList; }, }, }; </script> ``` CustomUploadList.vue 组件的代码如下: ```html <template> <el-upload-list class="custom-upload-list" :file-list="fileList"> <template slot-scope="{file}"> <div class="custom-list-item"> <img :src="file.url" class="custom-list-item-thumbnail"> <div class="custom-list-item-name">{{ file.name }}</div> <div class="custom-list-item-actions"> <el-button size="small" type="text" @click="handleRemove(file)">删除</el-button> </div> </div> </template> </el-upload-list> </template> <script> export default { props: { fileList: { type: Array, default: () => [], }, }, methods: { handleRemove(file) { const index = this.fileList.indexOf(file); if (index !== -1) { this.fileList.splice(index, 1); } }, }, }; </script> ``` 希望这个示例能够帮助到您。如果您有任何问题,请随时提出。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值