当前位置:   article > 正文

前端开发攻略---在Vue3项目中修改Element-Plus主题色_elconfigprovider改变颜色变亮

elconfigprovider改变颜色变亮

1、演示

2、安装依赖

npm i use-element-plus-theme -d

3、使用 

  1. import { useElementPlusTheme } from 'use-element-plus-theme'
  2. const { changeTheme } = useElementPlusTheme()
  3. const changePrimaryColor = () => {
  4. // 传入颜色
  5. changeTheme('red')
  6. }

4、演示代码

  1. <template>
  2. <el-color-picker v-model="currentColor" @change="handleChange" />
  3. <hr />
  4. <el-button type="primary" v-for="item in 50">按钮{{ item }}</el-button>
  5. </template>
  6. <script setup lang="ts">
  7. import { ref, onBeforeMount } from 'vue'
  8. // 引入插件
  9. import { useElementPlusTheme } from 'use-element-plus-theme'
  10. // 使用函数
  11. const { changeTheme } = useElementPlusTheme()
  12. // 当前颜色
  13. const currentColor = ref<string>('')
  14. // 组件挂载前使用上一次的颜色
  15. onBeforeMount(() => {
  16. const color = localStorage.getItem('currentPrimaryColor')
  17. currentColor.value = color as string
  18. changeTheme(color || '')
  19. })
  20. // 改变颜色
  21. const handleChange = (e: string) => {
  22. localStorage.setItem('currentPrimaryColor', currentColor.value)
  23. changeTheme(e)
  24. }
  25. </script>
  26. <style></style>

 

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/1021048
推荐阅读
相关标签
  

闽ICP备14008679号