vue 换肤
/* 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 换肤的更多相关文章
- vue+ element 动态换肤
转至 https://www.cnblogs.com/dengqichang/p/10364455.html 一.搭建好项目的环境. 二.根据ElementUI官网的自定义主题(http://elem ...
- vue 中使用sass实现主体换肤
有如下代码要实现换肤功能 <template> <div class="app-root" :class="themeClass"> & ...
- vue中利用scss实现整体换肤和字体大小设置
一.前言 利用Sass预处理实现换肤和字体大小调整. 思路及达到的效果:字体大小的适配使用window.devicePixelRatio的值和需要调整的差量进行控制.页面初始化是的字体适配可以根据de ...
- vue+less换肤,主题切换方案
新的项目对于客户自定义要求很高,然后换肤是其中一个很小的模块,经过了一段时间的摸索,看了许多文章,找到了几种方案. https://www.cnblogs.com/leiting/p/11203383 ...
- vue自定义switch开关,使用less支持换肤
实际项目用到了,记录一下,也方便以后使用,这样也可以避免为了使用一个switch,引入整个外部web框架: 也可以方便更好的理解是和使用less. 基础代码使用的是网上的,然后自己添加了less换肤, ...
- vue2.0-基于elementui换肤[自定义主题]
0. 直接上 预览链接 vue2.0-基于elementui换肤[自定义主题] 1. 项目增加主题组件 在项目的src/components下添加skin文件夹 skin文件获取地址 2. 项目增加自 ...
- element-ui 动态换肤
1.在安装好 element-ui@2.x 以后,首先安装sass-loader npm i sass-loader node-sass -D 2.安装 element-theme npm i ele ...
- vue-基于elementui换肤
思路: 生成不同的css颜色文件,每个文件内部命名前加上.custom-颜色值做命名空间. 然后app.vue里引入全部的颜色文件. 用户点击某颜色,就在body加上class:custom-00a5 ...
- 基于webpack4+vue-cli3项目的换肤功能
起因 最近因公司需求,需要实现主题换肤功能,不仅仅是颜色的更改,还需要包括图片,字体等文件等更换,因此在百度里各种实现方案后,决定根据scss+style-loader/useable做换肤. 项目开 ...
随机推荐
- Difference between C# compiler version and language version
Difference between C# compiler version and language version As nobody gives a good enough answer ...
- Android : 供应商原生开发套件 (VNDK)
一.VNDK概述 VNDK(Vendor Native Development Kit)是一组专门用于vendor实现其HAL的lib库,因为自Android 8.0以来,Google引入了Trebl ...
- Java:基础知识点
1. 面向对象的特征 (1)封装:把过程和数据包围起来,对数据的访问只能通过已定义的界面.即现实世界可以被描绘成一系列完全自治.封装的对象,这些对象通过一个受保护的接口访问其他对象:(2)继承:是一种 ...
- Hadoop、spark
http://blog.csdn.net/u011204847/article/details/51355272
- 010-数据结构-树形结构-B树[B-树]
一.概述 B 树就是常说的“B 减树(B- 树)”,又名平衡多路(即不止两个子树)查找树. 在计算机科学中,B树(英语:B-tree)是一种自平衡的树,能够保持数据有序.这种数据结构能够让查找数据.顺 ...
- [Spark News] Spark + GPU are the next generation technology
一.资源:Spark进行机器学习,支持GPU From:https://my.oschina.net/u/2306127/blog/1602291 为了使用Spark进行机器学习,支持GPU是必须的, ...
- *Scala API - 并发编程
- 树莓派搭建bt下载机、即是安装transmission
Transmission是一种BitTorrent客户端, 安装:sudo apt-get install transmission-daemon 给用户授权:sudo usermod -a -G p ...
- document.documentElement.clientHeight 和 document.body.clientHeight
document.documentElement.clientHeight 和 document.body.clientHeight 介绍 在进行一些网页效果处理的时候,经常碰到document.do ...
- RestTemplate连接池(转载)
出处:http://zhangzhi19861216.cnblogs.com/ spring-boot RestTemplate 连接池 以前我们项目都是基于Apache HttpClient 连接池 ...