/* eslint-disable */
// 设置文件
import setting from "@/setting.js"; const themeList = setting.theme.list; export default {
namespaced: true,
state: {
// 主题
list: themeList,
// 现在激活的主题 这应该是一个名字 不是对象
activeNumber: 0,
activeName: setting.theme.list[0].name
},
actions: {
/**
* @description 激活一个主题
* @param {Object} state vuex state
* @param {String} themeValue 需要激活的主题名称
*/
set({ state, commit, dispatch }, activeNumber) {
return new Promise(async resolve => {
// 检查这个主题在主题列表里是否存在
if (activeNumber < state.list.length) {
state.activeNumber = activeNumber;
state.activeName = state.list[activeNumber].name;
}
// 将 vuex 中的主题应用到 dom
commit("dom");
// 持久化
await dispatch(
"cptwebsite/db/set",
{
path: "theme.activeName",
value: state.activeName,
user: false
},
{ root: true }
);
// end
resolve();
});
},
/**
* @description 从持久化数据加载主题设置
* @param {Object} state vuex state
*/
load({ state, commit, dispatch }) {
return new Promise(async resolve => {
// store 赋值
let activeName = await dispatch(
"cptwebsite/db/get",
{
path: "theme.activeName",
defaultValue: state.activeName,
user: false
},
{ root: true }
); // 检查这个主题在主题列表里是否存在
const _index = state.list.findIndex(e => e.name === activeName);
if (_index > -1) {
state.activeNumber = _index;
state.activeName = activeName;
} else {
// 持久化
await dispatch(
"cptwebsite/db/set",
{
path: "theme.activeName",
value: state.activeName,
user: false
},
{ root: true }
);
}
// 将 vuex 中的主题应用到 dom
commit("dom");
// end
resolve();
});
}
},
mutations: {
/**
* @description 将 vuex 中的主题应用到 dom
* @param {Object} state vuex state
*/
dom(state) {
document.body.className = `theme-${state.activeName}`;
}
}
};

  

import { mapState } from 'vuex'
export default {
computed: {
...mapState('cptwebsite/theme', ['activeName'])
},
created () {
this._getLess()
},
methods: {
_getLess () {
return require(`@/assets/styles/theme/${this.activeName}/index.less`)
},
_getImage (filepath, filename) {
return require(`@/assets/templates/${this.activeName}/images/${filepath}/${filename}`)
},
_getPublicImage (filepath, filename) {
return require(`@/assets/images/${filepath}/${filename}`)
}
},
watch: {
activeName () {
this._getLess()
}
}
}

  

vue 换肤的更多相关文章

  1. vue+ element 动态换肤

    转至 https://www.cnblogs.com/dengqichang/p/10364455.html 一.搭建好项目的环境. 二.根据ElementUI官网的自定义主题(http://elem ...

  2. vue 中使用sass实现主体换肤

    有如下代码要实现换肤功能 <template> <div class="app-root" :class="themeClass"> & ...

  3. vue中利用scss实现整体换肤和字体大小设置

    一.前言 利用Sass预处理实现换肤和字体大小调整. 思路及达到的效果:字体大小的适配使用window.devicePixelRatio的值和需要调整的差量进行控制.页面初始化是的字体适配可以根据de ...

  4. vue+less换肤,主题切换方案

    新的项目对于客户自定义要求很高,然后换肤是其中一个很小的模块,经过了一段时间的摸索,看了许多文章,找到了几种方案. https://www.cnblogs.com/leiting/p/11203383 ...

  5. vue自定义switch开关,使用less支持换肤

    实际项目用到了,记录一下,也方便以后使用,这样也可以避免为了使用一个switch,引入整个外部web框架: 也可以方便更好的理解是和使用less. 基础代码使用的是网上的,然后自己添加了less换肤, ...

  6. vue2.0-基于elementui换肤[自定义主题]

    0. 直接上 预览链接 vue2.0-基于elementui换肤[自定义主题] 1. 项目增加主题组件 在项目的src/components下添加skin文件夹 skin文件获取地址 2. 项目增加自 ...

  7. element-ui 动态换肤

    1.在安装好 element-ui@2.x 以后,首先安装sass-loader npm i sass-loader node-sass -D 2.安装 element-theme npm i ele ...

  8. vue-基于elementui换肤

    思路: 生成不同的css颜色文件,每个文件内部命名前加上.custom-颜色值做命名空间. 然后app.vue里引入全部的颜色文件. 用户点击某颜色,就在body加上class:custom-00a5 ...

  9. 基于webpack4+vue-cli3项目的换肤功能

    起因 最近因公司需求,需要实现主题换肤功能,不仅仅是颜色的更改,还需要包括图片,字体等文件等更换,因此在百度里各种实现方案后,决定根据scss+style-loader/useable做换肤. 项目开 ...

随机推荐

  1. CSS 实现对号效果

    实现对号效果,一种思路是利用现成的符号,直接在网上搜索到 √,插入页面.另一种思路是本文要介绍的用 CSS 实现,思路是: 给块级元素设置宽度和高度 设置元素相邻的两个 border 旋转元素 HTM ...

  2. 后盾网lavarel视频项目---Vue项目使用vue-awesome-swiper轮播插件

    后盾网lavarel视频项目---Vue项目使用vue-awesome-swiper轮播插件 一.总结 一句话总结: vue中的插件的使用和js插件的使用一样的简单,只是vue插件的引入过程有些不同 ...

  3. C++ STL——异常

    目录 一 C++异常机制概述 二 栈解旋(unwinding) 三 异常接口的声明 四 异常类型和异常变量的生命周期 五 C++标准异常库 六 异常的继承 注:原创不易,转载请务必注明原作者和出处,感 ...

  4. LC 722. Remove Comments

    Given a C++ program, remove comments from it. The program source is an array where source[i] is the  ...

  5. 使用Pull解析器生成XML文件

    有些时候,我们需要生成一个XML文件,生成XML文件的方法有很多,如:可以只使用一个StringBuilder组拼XML内容,然后把内容写入到文件中:或者使用DOM API生成XML文件,或者也可以使 ...

  6. Node Newbie Error – NPM Refusing to Install Package as a Dependency of Itself

    46 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_ ...

  7. Scala安装配置和使用

  8. 1.ini读写操作

    一.使用 TIniFile implementationvar  ini:tinifile;  path:string;       {ini文件路径}  section,key:string;{表示 ...

  9. playbook常用操作

    playbook常用操作 1.检查playbook语法错误 ansible-playbook -i hosts deploy_coredns.yaml --syntax-check 2.查看playb ...

  10. 树莓派使用c语言控制管脚--wiringPi安装

    树莓派先安装git,然后安装库 命令如下 git clone https://github.com/WiringPi/WiringPi cd wiringPi ./build 测试--输出管脚信息 g ...