element-ui 插槽自定义样式怎么居中

场景:使用element-ui组件,scope内部自定义样式导致的错位
效果图在这里插入图片描述
解决思路: template标签可理解为一个内嵌组件,宽高重新定义,可在自定义内容外层套一层盒子,让盒子占满所有空间,再使用flex让内部元素居中
实现

  1. HTML呈现
<el-table>
...
<el-table-column
    label="工单状态"
    min-width="80">
    <template slot-scope="scope">
      <div class="flex flex-align-center flex-justify-center" style="height:100%;width:100%">
        <div class="orderstatus" :class="scope.row.color">{{scope.row.orderStatus}}</div>
      </div>
    </template>
</el-table-column>
...
</el-table>
  1. CSS呈现
.orderstatus{
   width: 0.66rem;
   height: 0.27rem;
   line-height: 0.27rem;
   border-radius: 0.04rem;
   border: 0.01rem solid #fff;
 }
 .blue{
   color: #3788FF;
   border: 0.01rem solid #3788FF;
   background: rgba(55,136,255,0.3);
 }
 .deepblue{
   color: #1E77F5;
   border: 0.01rem solid #1E77F5;
   background: rgba(30,119,245,0.3);
 }
 .yellow{
   color: #ED981A;
   border: 0.01rem solid #ED981A;
   background: rgba(237,152,26,0.3);
 }
 .green{
   color: #00B825;
   border: 0.01rem solid #00B825;
   background: rgba(0,184,37,0.3);
 }
 .red{
   color: #DC2E25;
   border: 0.01rem solid #DC2E25;
   background: rgba(220,46,37,0.3);
 }
.flex {
  display: flex;
}
.flex-align-center {
  align-items: center;
}
.flex-justify-center {
  justify-content: center;
}
  1. js部分
async init(){
	await require().then(res=>{
		this.tableData = res.data.map(item=>{
		  switch(item.docStatus){
		    case 0:
		      item.orderStatus = '待发布'
		      item.color = 'blue'
		      break;
		    case 1:
		      item.orderStatus = '待签收'
		      item.color = 'yellow'
		      break;
		    case 2:
		      item.orderStatus = '待提审'
		      item.color = 'deepblue'
		      break;
		    case 3:
		      item.orderStatus = '已验收'
		      item.color = 'green'
		      break;
		    case 4:
		      item.orderStatus = '已拒收'
		      item.color = 'red'
		      break;
		    default:
		      item.orderStatus = '待定'
		  }
		  return item;
		})
	})
}

相关推荐

  1. element ui 添加定义方法

    2024-07-15 06:32:02       31 阅读
  2. Vue中的定义指令

    2024-07-15 06:32:02       52 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-15 06:32:02       70 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-15 06:32:02       74 阅读
  3. 在Django里面运行非项目文件

    2024-07-15 06:32:02       62 阅读
  4. Python语言-面向对象

    2024-07-15 06:32:02       72 阅读

热门阅读

  1. Tick数据的清洗和1分钟K线合成

    2024-07-15 06:32:02       19 阅读
  2. App测试自动化工具UIAutomator2的使用

    2024-07-15 06:32:02       26 阅读
  3. React@16.x(57)Redux@4.x(6)- 实现 bindActionCreators

    2024-07-15 06:32:02       29 阅读
  4. PyTorch构建一个肺部CT图像分类模型来分辨肺癌

    2024-07-15 06:32:02       19 阅读
  5. Python学生信息管理系统的设计与实现

    2024-07-15 06:32:02       29 阅读
  6. SQL优化

    SQL优化

    2024-07-15 06:32:02      34 阅读
  7. RocketMQ

    RocketMQ

    2024-07-15 06:32:02      24 阅读
  8. SpringBoot实战:定时任务

    2024-07-15 06:32:02       21 阅读
  9. .NET 开源库技术栈汇总

    2024-07-15 06:32:02       20 阅读
  10. UDP 报文结构与注意事项全解析

    2024-07-15 06:32:02       28 阅读
  11. 深入理解Symfony框架中的数据验证机制

    2024-07-15 06:32:02       22 阅读
  12. OpenCV——实现视频图像的来回摆动的效果

    2024-07-15 06:32:02       19 阅读