当前位置: 首页 > news >正文

《Vue2.X 进阶知识点》- 防 ElementUI Divider 分割线

前言

使用 el-divider 背景为白色是没问题的。

在这里插入图片描述
但当背景换成其它颜色,问题就出现了!!

在这里插入图片描述
仔细看原来是两层,默认背景色是白色


想着把背景色改为透明应该能用,结果发现背面是一条实线,难怪要用白色遮挡…不符合我的需求…

在这里插入图片描述

实战

那就仿一个吧( Vue 组件)~ 。先看效果,上为 el-divider 组件,下为自定义组件。当背景为白色时差异不大(字体和线条颜色可自定义的):。
换成其它背景色就很明显:
在这里插入图片描述
以下是全部代码

<template><div class="my-divider" ><div class="line" :style="{width: leftWidth}" ></div><span class="label">{{label}}</span><div class="line" :style="{width: rightWidth}"></div></div>
</template><script>
export default {name: 'MyDivider',props: {// 文字label: {type: String,default: ''},// 文字位置,左 left,右 right,中 centercontentPosition: {type: String,default: 'center'},},watch: {contentPosition() {this.setLineWidth();}},data() {return {leftWidth: '50%',rightWidth: '50%',}},methods: {setLineWidth() {let p = this.contentPosition;switch (p) {case 'center': {this.leftWidth = '50%';this.rightWidth = '50%';break;}case 'left': {this.leftWidth = '10%';this.rightWidth = '90%';break;}case 'right': {this.leftWidth = '90%';this.rightWidth = '10%';break;}                }}},mounted() {this.setLineWidth();}
}
</script><style lang="stylus" scoped>
.my-divider {position: relative;width: 100%;display: flex;flex-direction: row;align-items:center;margin: 15px 0;color: #000;.line {background: #000;height: 1px;}.label {width auto;padding: 0 12px;text-align: center;transform: translateY(-1px);white-space: nowrap;// 不换行(单行)}
}
</style>

属性

参数说明类型必选默认值
label文字string
content-position文字位置,左 left,右 right,中 centerstringcenter

使用

<my-divider label="少年包青天" />
<my-divider label="少年包青天" content-position="left" />
<my-divider label="少年包青天" content-position="right" />
http://www.lryc.cn/news/269193.html

相关文章:

  • 【第十二课】KMP算法(acwing-831 / c++代码 / 思路 / 视频+博客讲解推荐)
  • JSON 简介
  • Impala4.x源码阅读笔记(三)——Impala如何管理Iceberg表元数据
  • Ubuntu2204配置samba
  • AVL树(超详解)
  • 禁止浏览器记住密码和自动填充 element-ui+vue
  • K8s实战-init容器
  • Vue3.2 自定义指令详解与实战
  • XV-3510CB振动陀螺仪传感器
  • 设计模式Java向
  • 图片素材管理软件Eagle for mac提高素材整理维度
  • Transformer各模块结构详解(附图)
  • Python遥感影像深度学习指南(2)-在 PyTorch 中创建自定义数据集和加载器
  • 韩版传奇 2 源码分析与 Unity 重制(三)客户端渲染管线
  • 深入浅出图解C#堆与栈 C# Heap(ing) VS Stack(ing) 第三节 栈与堆,值类型与引用类型
  • 分享好用的chatgpt
  • 【小白专用】C# 压缩文件 ICSharpCode.SharpZipLib.dll效果:
  • Protobuf 编码规则及c++使用详解
  • Kafka优异的性能是如何实现的?
  • (二)MaterializedMySQL具体实施步骤举例
  • 日志框架简介-Slf4j+Logback入门实践 | 京东云技术团队
  • c 语言, 随机数,一个不像随机数的随机数
  • Git三种方法从远程仓库拉取指定分支
  • 7.6分割回文串(LC131-M)
  • stata回归结果输出中,R方和F值到底是用来干嘛的?
  • Windows搭建RTMP视频流服务(Nginx服务器版)
  • IP地址SSL证书
  • 关于“Python”的核心知识点整理大全49
  • 爬虫学习(1)--requests模块的使用
  • 【Vue2 + ElementUI】el-table中校验表单