element-ui 插槽自定義樣式居中效果實(shí)現(xiàn)思路
場(chǎng)景:使用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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue WatchEffect函數(shù)創(chuàng)建高級(jí)偵聽器
watchEffect傳入的函數(shù)會(huì)被立即執(zhí)行一次,并且在執(zhí)行的過程中會(huì)收集依賴;其次,只有收集的依賴發(fā)生變化時(shí),watchEffect傳入的函數(shù)才會(huì)再次執(zhí)行2023-03-03Vue3前端做打印頁面信息實(shí)現(xiàn)打印功能(打印界面某個(gè)部分)
這篇文章主要介紹了如何使用vue3-print-nb依賴在Vue?3項(xiàng)目中實(shí)現(xiàn)頁面打印功能,提供了完整的代碼示例,大家可以根據(jù)項(xiàng)目需求選擇合適的打印方法,需要的朋友可以參考下2025-02-02Vue3中element-plus全局使用Icon圖標(biāo)的過程詳解
我們?cè)谟胿ue開發(fā)網(wǎng)站的時(shí)候,往往圖標(biāo)是起著很重要的作,這篇文章主要給大家介紹了關(guān)于Vue3中element-plus全局使用Icon圖標(biāo)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-01-01Vue3?封裝擴(kuò)展并簡(jiǎn)化Vuex在組件中的調(diào)用問題
這篇文章主要介紹了Vue3?封裝擴(kuò)展并簡(jiǎn)化Vuex在組件中的調(diào)用,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-01-01vant中l(wèi)ist的使用以及首次加載觸發(fā)兩次解決問題
這篇文章主要介紹了vant中l(wèi)ist的使用以及首次加載觸發(fā)兩次解決問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10vue學(xué)習(xí)之Vue-Router用法實(shí)例分析
這篇文章主要介紹了vue學(xué)習(xí)之Vue-Router用法,結(jié)合實(shí)例形式分析了Vue-Router路由原理與常見操作技巧,需要的朋友可以參考下2020-01-01Vue結(jié)合Element-Plus封裝遞歸組件實(shí)現(xiàn)目錄示例
本文主要介紹了Vue結(jié)合Element-Plus封裝遞歸組件實(shí)現(xiàn)目錄示例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04