位置: IT常识 - 正文

使用vue-antd动态切换主题(vue 动态tab)

编辑:rootadmin
这篇文章主要介绍了使用vue-antd动态切换主题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教 目录

推荐整理分享使用vue-antd动态切换主题(vue 动态tab),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:ant design vue 动态菜单,antd-vue-pro,vue中如何实现动态组件,ant design vue 动态菜单,antd vue pro 动态路由,antd vue pro 动态路由,antd vue pro 动态路由,antd vue pro 动态路由,内容如对您有帮助,希望把文章链接给更多的朋友!

vue-antd动态切换主题安装依赖Vue3.0 + Antd,修改antd主题色,配置全局cssvue-antd动态切换主题安装依赖1 webpack-theme-color-replacer: yarn add webpack-theme-color-replacer@1.3.222 less: yarn add less@2.7.23 less-loader: yarn add less-loader@7.0.2

在vue.config.js中加入配置

const createThemeColorReplacerPlugin = require("./plugin.config");const vueConfig = {  css: {    loaderOptions: {      less: {        lessOptions: {          modifyVars: {             //注意:此处不能给默认值,否则会导致主题色动态配置失败            // less vars,customize ant design theme            //'primary-color': '#2f54eb',            //'link-color': '#2f54eb',            //'border-radius-base': '4px'          },          // DO NOT REMOVE THIS LINE          javascriptEnabled: true,        },      },    },  },  configureWebpack: {    plugins: [createThemeColorReplacerPlugin()],  },  assetsDir: "static",};module.exports = vueConfig;

添加主题色更改方法,新建util文件夹创建plugin.config.js

const ThemeColorReplacer = require('webpack-theme-color-replacer')const generate = require('@ant-design/colors/lib/generate').defaultconst getAntdSerials = (color) => {  // 淡化(即less的tint)  const lightens = new Array(9).fill().map((t, i) => {    return ThemeColorReplacer.varyColor.lighten(color, i / 10)  })  const colorPalettes = generate(color)  const rgb = ThemeColorReplacer.varyColor.toNum3(color.replace('#', '')).join(',')  return lightens.concat(colorPalettes).concat(rgb)}const themePluginOption = {  fileName: 'css/theme-colors-[contenthash:8].css',  matchColors: getAntdSerials('#1890ff'), // 主色系列  // 改变样式选择器,解决样式覆盖问题  changeSelector (selector) {    switch (selector) {      case '.ant-calendar-today .ant-calendar-date':        return ':not(.ant-calendar-selected-date):not(.ant-calendar-selected-day)' + selector      case '.ant-btn:focus,.ant-btn:hover':        return '.ant-btn:focus:not(.ant-btn-primary):not(.ant-btn-danger),.ant-btn:hover:not(.ant-btn-primary):not(.ant-btn-danger)'      case '.ant-btn.active,.ant-btn:active':        return '.ant-btn.active:not(.ant-btn-primary):not(.ant-btn-danger),.ant-btn:active:not(.ant-btn-primary):not(.ant-btn-danger)'      case '.ant-steps-item-process .ant-steps-item-icon > .ant-steps-icon':      case '.ant-steps-item-process .ant-steps-item-icon>.ant-steps-icon':        return ':not(.ant-steps-item-process)' + selector      case '.ant-menu-horizontal>.ant-menu-item-active,.ant-menu-horizontal>.ant-menu-item-open,.ant-menu-horizontal>.ant-menu-item-selected,.ant-menu-horizontal>.ant-menu-item:hover,.ant-menu-horizontal>.ant-menu-submenu-active,.ant-menu-horizontal>.ant-menu-submenu-open,.ant-menu-horizontal>.ant-menu-submenu-selected,.ant-menu-horizontal>.ant-menu-submenu:hover':      case '.ant-menu-horizontal > .ant-menu-item-active,.ant-menu-horizontal > .ant-menu-item-open,.ant-menu-horizontal > .ant-menu-item-selected,.ant-menu-horizontal > .ant-menu-item:hover,.ant-menu-horizontal > .ant-menu-submenu-active,.ant-menu-horizontal > .ant-menu-submenu-open,.ant-menu-horizontal > .ant-menu-submenu-selected,.ant-menu-horizontal > .ant-menu-submenu:hover':        return '.ant-menu-horizontal > .ant-menu-item-active,.ant-menu-horizontal > .ant-menu-item-open,.ant-menu-horizontal > .ant-menu-item-selected,.ant-menu-horizontal:not(.ant-menu-dark) > .ant-menu-item:hover,.ant-menu-horizontal > .ant-menu-submenu-active,.ant-menu-horizontal > .ant-menu-submenu-open,.ant-menu-horizontal:not(.ant-menu-dark) > .ant-menu-submenu-selected,.ant-menu-horizontal:not(.ant-menu-dark) > .ant-menu-submenu:hover'      case '.ant-menu-horizontal > .ant-menu-item-selected > a':      case '.ant-menu-horizontal>.ant-menu-item-selected>a':        return '.ant-menu-horizontal:not(ant-menu-light):not(.ant-menu-dark) > .ant-menu-item-selected > a'      case '.ant-menu-horizontal > .ant-menu-item > a:hover':      case '.ant-menu-horizontal>.ant-menu-item>a:hover':        return '.ant-menu-horizontal:not(ant-menu-light):not(.ant-menu-dark) > .ant-menu-item > a:hover'      default :        return selector    }  }}const createThemeColorReplacerPlugin = () => new ThemeColorReplacer(themePluginOption)module.exports = createThemeColorReplacerPlugin

添加util.js文件

import client from "webpack-theme-color-replacer/client";import generate from "@ant-design/colors/lib/generate";function getAntdSerials(color) {  // 淡化(即less的tint)  const lightens = new Array(9).fill().map((t, i) => {    return client.varyColor.lighten(color, i / 10);  });  // colorPalette变换得到颜色值  const colorPalettes = generate(color);  const rgb = client.varyColor.toNum3(color.replace("#", "")).join(",");  return lightens.concat(colorPalettes).concat(rgb);}function changeColor(newColor) {  var options = {    newColors: getAntdSerials(newColor), // new colors array, one-to-one corresponde with `matchColors`    changeUrl(cssUrl) {      return `/${cssUrl}`; // while router is not `hash` mode, it needs absolute path    },  };  return client.changer.changeColor(options, Promise);}export default {  updateTheme(newPrimaryColor) {    const hideMessage = () => console.log("正在切换主题!", 0);    changeColor(newPrimaryColor).finally((t) => {      setTimeout(() => {        hideMessage();      });    });  },};

然后在main.js中引入为Vue原型prototype中的方法

import utils from "./utils"Vue.prototype.$u = utils//注意antd样式的引入必须由css改为less引入- import 'ant-design-vue/dist/antd.css';+ import 'ant-design-vue/dist/antd.less';

然后项目启动起来后调用Vm.$u.updateTheme方法即可动态改变主题色。

注意该方法传值必须传十六进制的颜色,如果传颜色对应的英文字符可能会出错.

使用vue-antd动态切换主题(vue 动态tab)

如果自定义组件或者元素也需要统一管理主题色,则在assets目录新建main.less

@import "~ant-design-vue/dist/antd.less";#home {  color: @primary-color;}

在main.less中引入antd的样式,然后antd的主题色是@primary-color, 直接使用即可

然后在main.js中直接引入main.less

- import 'ant-design-vue/dist/antd.less';+ import "./assets/css/main.less"Vue3.0 + Antd,修改antd主题色,配置全局css

1.在vue.config.js里修改配置

module.exports = {  css: {    loaderOptions: {      less: {        lessOptions: {          modifyVars: {            'primary-color': '#3d62ff',// 修改全局主题色          },          javascriptEnabled: true,        },      },    },    extract: true, // 解决开发模式,打包时未提取CSS的问题  }}

2.把main.ts中的import ‘ant-design-vue/dist/antd.css’;

修改为 import ‘ant-design-vue/dist/antd.less’;

修改css为less的时候,会报错 .bezierEasingMixin()

解决方法是:先卸载less-loader

npm uninstall -D less-loader

再安装less-loader@6.0.0

npm install -D less-loader@6.0.0

然后重新运行项目即可

以上为个人经验,希望能给大家一个参考,也希望大家多多支持本站。

本文链接地址:https://www.jiuchutong.com/zhishi/304790.html 转载请保留说明!

上一篇:phpcms上传不了图片怎么办(php实现上传图片功能)

下一篇:一起爬山吗?《隐秘的角落》为什么译成Cat's Cradle?(你要和我一起爬山吗)

  • 什么是增值税扣缴义务
  • 小规模纳税人销售农产品税率是多少
  • 捐赠支出增值税
  • 车辆购置税如何计算
  • 投资管理公司成立的条件
  • 自然人系统怎么申报个人所得税
  • 电信要收取安装费吗
  • 税款状态已缴款未入库
  • 同一控制下企业合并取得的长期股权投资
  • 没有土地使用证的房子拆迁怎么办
  • 公益性捐赠支出属于营业外支出吗
  • 一般纳税人注销库存需要补交税吗
  • 车过户怎么处理
  • 应收账款多久收回合适
  • 预存送返利的帐户怎么查
  • 企业拿到产权证后是否还需要缴纳土地使用税呢?
  • 合同签了发票开了钱没给怎么办
  • 小微企业增值税最新优惠政策
  • 外汇网上申报操作流程图
  • 小微企业的特点及经营模式举例
  • 公司注销财务账需要保存几年
  • 小规模开税票怎么开
  • 子公司向母公司借款
  • 退了货的发票还能用吗
  • 股东分红账务处理后报表怎么处理
  • 资产处置损益是什么科目
  • 印花税的会计处理是什么
  • 在建工程变更建设单位
  • 赠与合同要公证吗有效吗
  • 前端获取当前地址
  • 凤尾蕨的养殖方法
  • 投资性房地产转换日公允价值大于账面价值
  • php read
  • php时间不对
  • laravel框架实现增删改查
  • 财务人员如何管控费用支出
  • 待安置期间生活补助费多少钱
  • 销售方运输发票怎么做账?
  • 出售生产设备的会计分录
  • 图像去噪的原理
  • 发票失控进项转出
  • python中的sum函数怎么用
  • 水利建设基金的计费方式
  • 织梦cms怎么样
  • 帝国cms如何使用
  • 以非货币性资产对外投资会计处理
  • 公司的融资租赁有哪些
  • 税收分类口诀
  • 车辆购置税能否融资租赁
  • 外贸企业出口退税
  • 金融商品转让一半增值税
  • sqlalchemy mongodb
  • 产品的运输费用分录
  • 免税企业税金及附加计算
  • 股东权益合计等于净资产吗
  • 从厂家直接拿货需要什么条件
  • 生产成本如何结转
  • 没有海关完税凭证怎么入账
  • 进项抵扣怎么操作
  • 一般纳税人购买原材料会计分录
  • 补发工资怎么补发
  • 商业承兑汇票和银行承兑汇票的区别
  • 小微企业免征增值税优惠
  • Advanced Pagination for MySQL(mysql高级分页)
  • Win7旗舰版系统文件名称
  • AppleMobileDeviceService.exe是什么进程?AppleMobileDeviceService.exe是病毒吗?
  • solaris ssh offline
  • xp系统快捷启动按哪个
  • win8metro版桌面安卓下载
  • linux开启samba服务
  • shader开发实战
  • javascript屏蔽元素
  • opengl自学
  • JAVASCRIPT IE 与 FF 中兼容写法记录
  • jQuery中trigger()与bind()用法分析
  • 批处理提取文件夹中的文件
  • jquery插件是干什么的
  • 增值税税率最新
  • 打印个人住房信息查询记录需要什么资料
  • 走逃失踪纳税人如何处理
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设