vue中的el-button樣式自定義方式
vue el-button樣式自定義
按鈕的三種狀態(tài)
/* 更改elememt-ui地固定樣式 */ /*按鈕的背景顏色樣式*/ .el-button--primary { background-color: rgb(247, 146, 146) !important; } /*鼠標(biāo)經(jīng)過*/ .el-button--primary:hover { background-color: rgb(178, 253, 144) !important; } /*鼠標(biāo)按下*/ .el-button--primary:focus { background-color: rgb(159, 230, 240) !important; }
還可以添加背景圖片
但每一個樣式后面都要添加!important即可改變按鈕的默認(rèn)樣式
按鈕的其他樣式 和平時一樣添加就好了
.el-button--primary { background-color: #105EED !important; color: white !important; font-size: 20px; height: 66px; }
用按鈕切換界面
<el-button type="info" data-id="2" plain :style="{'background-color': tab == 2 ? '#839DB9' : '','color': tab == 2 ? 'white' : 'black'} " @click="tabChange">11111</el-button> <el-button type="info" data-id="3" plain :style="{'background-color': tab == 3 ? '#839DB9' : '','color': tab == 3 ? 'white' : 'black'} " @click="tabChange">2222</el-button> <div v-show="tab==2" class="width48"></div> <div v-show="tab==3" class="width48"></div>
tabChange(e) { let tabid = e.currentTarget.dataset.id this.tab = tabid },
element button自定義圖標(biāo)
實現(xiàn)效果
如圖,我想實現(xiàn)二維碼的圖片可以根據(jù)不同狀態(tài)進(jìn)行disabled的切換,本來是用兩個img實現(xiàn)的,但是img還需要設(shè)置圖片不可點擊,雖然css使用cursor:no-drop也能實現(xiàn),后來突然想到button就默認(rèn)支持disabled呀,我只用把這個二維碼的圖片設(shè)置為button的自定義圖標(biāo),我就可以使用button的disabled去控制是否可以點擊了
代碼實現(xiàn)
button的icon屬性自定義一個圖標(biāo)名稱,這個自定義的圖標(biāo)名稱會默認(rèn)添加到button下i標(biāo)簽的class上,我們只需要設(shè)置i標(biāo)簽的樣式就可以了
<el-button slot="reference" type="text" icon="el-icon-my-qr-code" :class=" //控制顯示圖標(biāo)的顏色 hasIncludeHttpText(row) ? 'qr-code-icon-default' : 'qr-code-icon-disabled' " :disabled="!hasIncludeHttpText(row)" ></el-button>
設(shè)置樣式需要注意加/deep/,因為這些樣式不是在當(dāng)前組件的,所以不加/deep/設(shè)置是沒有用的,當(dāng)然如果不加scoped就不用加/deep/了
.qr-code-icon-default { /deep/ .el-icon-my-qr-code { background: url('~@home/assets/images/qr-code-icon.svg') no-repeat; } } .qr-code-icon-disabled { /deep/ .el-icon-my-qr-code { background: url('~@home/assets/images/disabled-qr-code-icon.svg') no-repeat; } } /deep/.el-icon-my-qr-code { font-size: 16px; background-size: cover; } /deep/ .el-icon-my-qr-code:before { content: '替'; font-size: 16px; visibility: hidden; }
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
詳解axios 全攻略之基本介紹與使用(GET 與 POST)
本篇文章主要介紹了axios 全攻略之基本介紹與使用(GET 與 POST),詳細(xì)的介紹了axios的安裝和使用,還有 GET 與 POST方法,有興趣的可以了解一下2017-09-09vue項目登錄頁面實現(xiàn)記住用戶名和密碼的示例代碼
本文主要介紹了vue項目登錄頁面實現(xiàn)記住用戶名和密碼的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07vue2使用ts?vue-class-component的過程
vue-property-decorator?是一個?Vue.js?的裝飾器庫,它提供了一些裝飾器來讓你在?Vue?組件中定義屬性、計算屬性、方法、事件等,本文給大家介紹vue2使用ts?vue-class-component的相關(guān)知識,感興趣的朋友一起看看吧2023-11-11