@TOC

有对于element中switch的用法

el-switch的具体用法

实现的效果图

具体实现步骤:

(1)增加html代码的显示,此处写了class="switch"类名,是为了防止造成全局款式的净化。

 <el-table-column label="高低架" align="center">     <template slot-scope="scope">         <el-switch             class="switch"             v-model="scope.row.status"             :active-value="0"             :inactive-value="1"             active-text="上架"             inactive-text="下架"         >         </el-switch>     </template> </el-table-column>

(2)批改el-switch的默认款式
我的款式是写在全局款式文件main.css中的,如果是想在el-switch所在文件中去批改款式的话,肯定要留神style中不能有scoped属性,否则写的款式可能会不失效。然而如果去掉scoped的话,款式也会作用于全局,有可能会造成全局净化,所以倡议在款式里面加一个全局类名。
小知识点:在应用vue框架的时候,给style标签增加scoped属性,示意该style标签所蕴含的款式仅仅作用于以后的vue组件,不会产生款式全局净化的状况,一个利用中所有vue组件都加上该属性,则实现了款式的模块化

/* switch按钮款式 */.switch .el-switch__label {    position: absolute;    display: none;    color: #fff !important;}/*关上时文字地位设置*/.switch .el-switch__label--right {    z-index: 1;}/* 调整关上时文字的显示位子 */.switch .el-switch__label--right span{    margin-right: 9px;}/*敞开时文字地位设置*/.switch .el-switch__label--left {    z-index: 1;}/* 调整敞开时文字的显示位子 */.switch .el-switch__label--left span{    margin-left: 9px;}/*显示文字*/.switch .el-switch__label.is-active {    display: block;}/* 调整按钮的宽度 */.switch.el-switch .el-switch__core,.el-switch .el-switch__label {     width: 70px !important;     margin: 0;}