当前位置:   article > 正文

element组件暗黑模式的开启(elementplus 后面的版本支持暗黑模式 )\_element ui select 暗黑

element ui select 暗黑

1.在老版本里面可以使用filter去过滤

  1. html {
  2. filter: invert(1) hue-rotate(.5turn);
  3. }

2.图片的样式也会受到影响 所以需要将上面的代码重新写一下

  1. img {
  2. filter: invert(1) hue-rotate(.5turn);
  3. }

element版本在支持暗黑模式的情况下

1.我们要先在main.js导入暗黑样式

import 'element-plus/theme-chalk/dark/css-vars.css'

2. 通过创建一个组件来控制是否在html上面添加样式dark

  1. <template>
  2. <div class="dark-box">
  3. <el-button text class="switch" :class="isDark ? 'isDark-switch' : 'noDark-switch'" @click="toggleDark">
  4. <el-icon v-if="isDark">
  5. <svg viewBox="0 0 24 24">
  6. <path
  7. d="M6.05 4.14l-.39-.39a.993.993 0 0 0-1.4 0l-.01.01a.984.984 0 0 0 0 1.4l.39.39c.39.39 1.01.39 1.4 0l.01-.01a.984.984 0 0 0 0-1.4zM3.01 10.5H1.99c-.55 0-.99.44-.99.99v.01c0 .55.44.99.99.99H3c.56.01 1-.43 1-.98v-.01c0-.56-.44-1-.99-1zm9-9.95H12c-.56 0-1 .44-1 .99v.96c0 .55.44.99.99.99H12c.56.01 1-.43 1-.98v-.97c0-.55-.44-.99-.99-.99zm7.74 3.21c-.39-.39-1.02-.39-1.41-.01l-.39.39a.984.984 0 0 0 0 1.4l.01.01c.39.39 1.02.39 1.4 0l.39-.39a.984.984 0 0 0 0-1.4zm-1.81 15.1l.39.39a.996.996 0 1 0 1.41-1.41l-.39-.39a.993.993 0 0 0-1.4 0c-.4.4-.4 1.02-.01 1.41zM20 11.49v.01c0 .55.44.99.99.99H22c.55 0 .99-.44.99-.99v-.01c0-.55-.44-.99-.99-.99h-1.01c-.55 0-.99.44-.99.99zM12 5.5c-3.31 0-6 2.69-6 6s2.69 6 6 6s6-2.69 6-6s-2.69-6-6-6zm-.01 16.95H12c.55 0 .99-.44.99-.99v-.96c0-.55-.44-.99-.99-.99h-.01c-.55 0-.99.44-.99.99v.96c0 .55.44.99.99.99zm-7.74-3.21c.39.39 1.02.39 1.41 0l.39-.39a.993.993 0 0 0 0-1.4l-.01-.01a.996.996 0 0 0-1.41 0l-.39.39c-.38.4-.38 1.02.01 1.41z"
  8. fill="currentColor"></path>
  9. </svg>
  10. </el-icon>
  11. <el-icon v-else>
  12. <svg viewBox="0 0 24 24">
  13. <path
  14. d="M11.01 3.05C6.51 3.54 3 7.36 3 12a9 9 0 0 0 9 9c4.63 0 8.45-3.5 8.95-8c.09-.79-.78-1.42-1.54-.95A5.403 5.403 0 0 1 11.1 7.5c0-1.06.31-2.06.84-2.89c.45-.67-.04-1.63-.93-1.56z"
  15. fill="currentColor"></path>
  16. </svg>
  17. </el-icon>
  18. </el-button>
  19. </div>
  20. </template>
  21. <script setup >
  22. import { ref } from 'vue'
  23. const isDark = ref(true)
  24. const toggleDark = () => {
  25. isDark.value = !isDark.value
  26. const html = document.querySelector('html')
  27. if (html) {
  28. if (isDark.value) {
  29. html.classList.remove("dark");
  30. html.classList.add("light");
  31. } else {
  32. html.classList.remove("light");
  33. html.classList.add("dark");
  34. }
  35. }
  36. }
  37. </script>
  38. <style scoped>
  39. .dark-box {
  40. margin-right: 20px;
  41. }
  42. .switch {
  43. width: 40px;
  44. height: 20px;
  45. border: 1px solid #dcdfe6;
  46. border-radius: 10px;
  47. box-sizing: border-box;
  48. cursor: pointer;
  49. padding-bottom: 0;
  50. padding-top: 0px;
  51. background-color: #ebeef5 !important;
  52. font-size: 12px;
  53. }
  54. .isDark-switch .el-icon {
  55. background-color: #fff !important;
  56. padding: 2px;
  57. border-radius: 50%;
  58. color: #000;
  59. margin-left: -8px;
  60. }
  61. .noDark-switch {
  62. background-color: rgb(8, 8, 8) !important;
  63. }
  64. .noDark-switch .el-icon {
  65. color: #fff;
  66. margin-left: 15px;
  67. }
  68. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/82010
推荐阅读
相关标签
  

闽ICP备14008679号