Vue+Element?switch組件的使用示例代碼詳解
代碼如下所示:
<el-table-column label="商品狀態(tài)" align="center"> <template slot-scope="{row}"> <el-switch v-model="row.goods_state" class="switch" :active-value="1" :inactive-value="0" active-text="上架" inactive-text="下架" @change="change($event,row)" /> </template> </el-table-column>
參數(shù)說明:
width | switch 的寬度(像素) |
active-text | switch 打開時(shí)的文字描述 |
inactive-text | switch 關(guān)閉時(shí)的文字描述 |
active-value | switch 打開時(shí)的值 |
inactive-value | switch 關(guān)閉時(shí)的值 |
active-color | switch 打開時(shí)的背景色 |
inactive-color | switch 關(guān)閉時(shí)的背景色 |
完整代碼:
<el-table-column label="商品狀態(tài)" align="center"> <template slot-scope="{row}"> <el-switch v-model="row.goods_state" class="switch" :active-value="1" :inactive-value="0" @change="change($event,row)" /> </template> </el-table-column> <script> methods: { //狀態(tài)切換 change(data, row) { console.log(data); console.log(row); //此處可以請求后端接口更改商品狀態(tài) }, } }; </script>
如何讓文字在按鈕中顯示如以下這樣
解決辦法:加入以下css樣式
/* switch按鈕樣式 */ .switch .el-switch__label { position: absolute; display: none; color: #fff !important; } /*打開時(shí)文字位置設(shè)置*/ .switch .el-switch__label--right { z-index: 1; } /* 調(diào)整打開時(shí)文字的顯示位子 */ .switch .el-switch__label--right span{ margin-right: 9px; } /*關(guān)閉時(shí)文字位置設(shè)置*/ .switch .el-switch__label--left { z-index: 1; } /* 調(diào)整關(guān)閉時(shí)文字的顯示位子 */ .switch .el-switch__label--left span{ margin-left: 9px; } /*顯示文字*/ .switch .el-switch__label.is-active { display: block; } /* 調(diào)整按鈕的寬度 */ .switch.el-switch .el-switch__core, .el-switch .el-switch__label { width: 60px !important; margin: 0; }
到此這篇關(guān)于Vue+Element switch組件的使用的文章就介紹到這了,更多相關(guān)Vue Element switch組件內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue自定義指令結(jié)合阿里云OSS優(yōu)化圖片的實(shí)現(xiàn)方法
這篇文章主要介紹了Vue自定義指令結(jié)合阿里云OSS優(yōu)化圖片的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11詳解vue express啟動(dòng)數(shù)據(jù)服務(wù)
本篇文章主要介紹了vue express啟動(dòng)數(shù)據(jù)服務(wù),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07vue 點(diǎn)擊其他區(qū)域關(guān)閉自定義div操作
這篇文章主要介紹了vue 點(diǎn)擊其他區(qū)域關(guān)閉自定義div操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07Vue項(xiàng)目中接口調(diào)用的詳細(xì)講解
應(yīng)公司需求,接口需要對接vue,記錄一下碰到的問題,下面這篇文章主要給大家介紹了關(guān)于Vue項(xiàng)目中接口調(diào)用的詳細(xì)講解,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-07-07