element-ui 插槽自定義樣式居中效果實(shí)現(xiàn)思路
場景:使用element-ui組件,scope內(nèi)部自定義樣式導(dǎo)致的錯(cuò)位
效果圖:

解決思路: template標(biāo)簽可理解為一個(gè)內(nèi)嵌組件,寬高重新定義,可在自定義內(nèi)容外層套一層盒子,讓盒子占滿所有空間,再使用flex讓內(nèi)部元素居中
實(shí)現(xiàn):
HTML呈現(xiàn)
<el-table>
...
<el-table-column
label="工單狀態(tài)"
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>CSS呈現(xiàn)
.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;
}js部分
async init(){
await require().then(res=>{
this.tableData = res.data.map(item=>{
switch(item.docStatus){
case 0:
item.orderStatus = '待發(fā)布'
item.color = 'blue'
break;
case 1:
item.orderStatus = '待簽收'
item.color = 'yellow'
break;
case 2:
item.orderStatus = '待提審'
item.color = 'deepblue'
break;
case 3:
item.orderStatus = '已驗(yàn)收'
item.color = 'green'
break;
case 4:
item.orderStatus = '已拒收'
item.color = 'red'
break;
default:
item.orderStatus = '待定'
}
return item;
})
})
}到此這篇關(guān)于element-ui 插槽自定義樣式怎么居中的文章就介紹到這了,更多相關(guān)element-ui 插槽自定義樣式內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
VUE開發(fā)分布式醫(yī)療掛號(hào)系統(tǒng)的醫(yī)院設(shè)置頁面步驟
這篇文章主要為大家介紹了VUE開發(fā)分布式醫(yī)療掛號(hào)系統(tǒng)的醫(yī)院設(shè)置頁面步驟,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-04-04
Vue 中指令v-bind動(dòng)態(tài)綁定及與v-for結(jié)合使用詳解
這篇文章主要為大家介紹了Vue 中指令v-bind動(dòng)態(tài)綁定及與v-for結(jié)合使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09
Vue項(xiàng)目全局配置頁面緩存之按需讀取緩存的實(shí)現(xiàn)詳解
這篇文章主要給大家介紹了關(guān)于Vue項(xiàng)目全局配置頁面緩存之實(shí)現(xiàn)按需讀取緩存的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起看看吧2018-08-08
Vue3響應(yīng)式對象是如何實(shí)現(xiàn)的(1)
這篇文章主要介紹了Vue3響應(yīng)式對象是如何實(shí)現(xiàn)的,文章圍繞主題展開詳細(xì)的內(nèi)容介紹具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-08-08
vue操作下拉選擇器獲取選擇的數(shù)據(jù)的id方法
今天小編就為大家分享一篇vue操作下拉選擇器獲取選擇的數(shù)據(jù)的id方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
3分鐘帶你快速認(rèn)識(shí)Vue3中的v-model
model在vue里面實(shí)現(xiàn)雙向綁定,通過父節(jié)點(diǎn)向子節(jié)點(diǎn)傳遞參數(shù),子節(jié)點(diǎn)通過操作再回傳給父節(jié)點(diǎn)的變量,有點(diǎn)像prop和$emit組合使用,下面這篇文章主要給大家介紹了關(guān)于Vue3中v-model的相關(guān)資料,需要的朋友可以參考下2022-11-11

