vue 一键换肤

思路,可以运用element 内的组件配合css样式
操作:页面中只需要添加一键换肤的操作时间进行配色即可。一般就是两种颜色,默认色和改变色,我的需求是改背景色,不改字体色,因为字体的色值颜色太多。我用了本地存储localStorage加store。

如果需要透明度,注意的是要给所有的组件背景色初始值 透明度 background: rgba(255, 255, 255, 0.05), 这个设置一般是在全局的css样式李设置,具体就要自己去元素李点击查看了;
不需要可以忽略。

 <el-button type="info" plain @click="changeSkin">一键换肤</el-button>

 定义一个初始色
   data () {
    return {
      themeColor: '#061729'
    }
  },
 然后时间中进行更改存值即可
 changeSkin () {
  if (this.themeColor === '#061729') {
    this.themeColor = '#031E3C' // 切换到新主题
    this.$store.commit('setThemeBackgroundColor', this.themeColor)
  } else {
    this.themeColor = '#061729' // 切换到原主题
    this.$store.commit('setThemeBackgroundColor', this.themeColor)
  }
  window.localStorage.setItem('theme', this.themeColor) // 保存当前主题色到localStorage
  // this.visible = !this.visible
},

在需要的页面进行计算属性

  computed: {
    currentComponentBackgroundColor () {
      return this.themeColor
    }
  },

页面渲染

<div class="header-container" :style="{background: currentComponentBackgroundColor}"></div>

在store 中存储

const state = {
  themeBackgroundColor:  window.localStorage.getItem('theme') // '#061729' // 默认主背景色
}

const mutations = {
  setThemeBackgroundColor (state, color) {
    state.themeBackgroundColor = color
  }
}
即可。

相关推荐

  1. vue

    2024-01-22 17:28:01       55 阅读
  2. VUE3 /根据主题动态切换图片

    2024-01-22 17:28:01       47 阅读
  3. uniapp

    2024-01-22 17:28:01       57 阅读
  4. armbian

    2024-01-22 17:28:01       39 阅读
  5. 安卓壁纸

    2024-01-22 17:28:01       31 阅读
  6. apk包名工具

    2024-01-22 17:28:01       38 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-22 17:28:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-22 17:28:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-22 17:28:01       82 阅读
  4. Python语言-面向对象

    2024-01-22 17:28:01       91 阅读

热门阅读

  1. Python经典例题20道

    2024-01-22 17:28:01       62 阅读
  2. Hive之set参数大全-11

    2024-01-22 17:28:01       47 阅读
  3. PiflowX组件-PostgresCdc

    2024-01-22 17:28:01       55 阅读
  4. 柠檬微趣面试准备

    2024-01-22 17:28:01       50 阅读
  5. 使用helm部署 redis 单机版

    2024-01-22 17:28:01       53 阅读
  6. NGINX网站服务

    2024-01-22 17:28:01       44 阅读
  7. CCF ---- 仓库规划

    2024-01-22 17:28:01       46 阅读
  8. vim命令打开日志中文乱码问题解决

    2024-01-22 17:28:01       50 阅读
  9. 解决Unity WebGLInput插件全屏输入的问题

    2024-01-22 17:28:01       56 阅读