VUE Element ui el-switch文字在开关里面显示

198 阅读1分钟

image.png

  • ::v-deep .el-switch__label: 将开关上的文本标签(如“开”和“关”)的默认显示方式设置为 display: none,即隐藏文本。
  • ::v-deep .el-switch__label--right 和  ::v-deep .el-switch__label--left: 分别控制当开关为开启(右侧)或关闭(左侧)时,文本的位置。通过 right: 20px 和 left: 20px 定位文本。
  • ::v-deep .el-switch__label.is-active: 当开关为开启时,设置标签的 display 为 block,使其显示出来。
  • .el-switch .el-switch__core, .el-switch .el-switch__label: 设置开关核心区域和标签的宽度为 55px,确保整体外观的统一。
<el-switch
     v-model="scope.row.scriptState"
     class="switchStyle" 
     :width="60"          
      active-text="启用"
      inactive-text="停用"
      @change="getSwitchChange(scope.row)">
 </el-switch>
<style lang="scss" scoped>

::v-deep .el-switch__label {
  position: absolute;
  display: none;
  color: #fff;
}
/*打开时文字位置设置*/
::v-deep .el-switch__label--right {
  z-index: 1;
  right: 20px;
}
/*关闭时文字位置设置*/
::v-deep .el-switch__label--left {
  z-index: 1;
  left: 20px;
}
/*显示文字*/
::v-deep .el-switch__label.is-active {
  display: block;
}
::v-deep .el-switch .el-switch__core,
.el-switch .el-switch__label {
  width: 55px;
}
</style>