ant design vue 在线自定义更换主题颜色

本文介绍如何使用Vue和AntDesign实现网站主题颜色的动态更换,通过配置和代码示例,展示了如何定制主题颜色,使网站更具个性化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先看demo
源码
原文地址
看到ant design pro 上的 主题颜色更换 感觉挺酷的 就研究了一下 , 因为最近想用vue 重写一版博客 所有就 用的 vue + ant design 做的这个demo

1 创建项目

用vue cli 创建项目之后 需要先安装以下两个 插件 第一个是 ui 都知道 第二个是 用来改变颜色的插件
“ant-design-vue”: “^1.4.8”,
“antd-theme-generator”: “^1.1.7”

在 main.js 中 一定要 导入 antd.less

import ‘ant-design-vue/dist/antd.less’
import Antd from ‘ant-design-vue’
Vue.config.productionTip = false
Vue.use(Antd)

2 创建color.js

在跟目录下创建 color.js 内容为

const path = require('path');
const { generateTheme, getLessVars } = require('antd-theme-generator');
// ant-design-vue/dist/antd.less
const options = {
 antDir: path.join(__dirname, './node_modules/ant-design-vue'), //对应具体位置
 stylesDir: path.join(__dirname, './src/styles'),    //对应具体位置
 varFile: path.join(__dirname, './src/styles/variables.less'), //对应具体位置
 mainLessFile: path.join(__dirname, './src/styles/index.less'), //对应具体位置
 themeVariables: [
 '@primary-color',
 '@secondary-color',
 '@text-color',
 '@text-color-secondary',
 '@heading-color',
 '@layout-body-background',
 '@btn-primary-bg',
 '@layout-header-background'
  ],
 indexFileName: 'index.html',
 outputFilePath: path.join(__dirname, './public/color.less'),
}
generateTheme(options).then(less => {
 console.log('Theme generated successfully');
})
.catch(error => {
 console.log('Error', error);
});

3 创建style

在src目录下 创建 style 文件夹

在文件夹下创建 index.less variables.less 两个文件

其中 index.less 为空

variables.less 内容为

@import “~/ant-design-vue/lib/style/themes/default.less”;
@link-color: #00375B;
@primary-color: rgb(138, 164, 182);
.primary-color{
color:@primary-color
}

4 更改 html

在public 下的index.html 中 增加以下代码

注: 这段代码加在body末尾 别在head 上

 <link rel="stylesheet/less" type="text/css" href="/color.less" />
 <script>
 window.less = {
 async: false,
 env: 'production'
        };
 </script>
 <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/less.js/2.7.2/less.min.js"></script>

5 更改 package.json

“serve”: “node color && vue-cli-service serve”,
“build”: “node color && vue-cli-service build”,
6 更改颜色

window.less
.modifyVars({
‘@primary-color’: this.color,
‘@link-color’: this.color,
‘@btn-primary-bg’: this.color
}) 这个方法用来更换颜色

<template>
 <div class="cont">
 <a-row>
 <a-col :span="12" :offset="6">
 <a-divider>设置颜色</a-divider>
 <h2>预设颜色</h2>
 <div class="yscont">
 <div class="ysitem" style="background:#3e91f7" @click="click('#3e91f7')"></div>
 <div class="ysitem" style="background:#e23c39" @click="click('#e23c39')"></div>
 <div class="ysitem" style="background:#e96033" @click="click('#e96033')"></div>
 <div class="ysitem" style="background:#f0af41" @click="click('#f0af41')"></div>
 <div class="ysitem" style="background:#58bfc1" @click="click('#58bfc1')"></div>
 <div class="ysitem" style="background:#72c140" @click="click('#72c140')"></div>
 <div class="ysitem" style="background:#3258e3" @click="click('#3258e3')"></div>
 <div class="ysitem" style="background:#6839c9" @click="click('#6839c9')"></div>
 </div>
 <h2>自定义颜色</h2>
 <a-input type="color" style="width:100px;margin-bottom:10px" v-model="color" @change="huan"></a-input>
 <a-divider>效果展示</a-divider>
 <a-button-group style="margin-right:10px">
 <a-button>Cancel</a-button>
 <a-button type="primary">OK</a-button>
 </a-button-group>
 <a-button-group>
 <a-button type="primary">L</a-button>
 <a-button>M</a-button>
 <a-button>M</a-button>
 <a-button type="dashed">R</a-button>
 </a-button-group>
 <br />
 <a-radio-group>
 <a-radio-button value="a">Hangzhou</a-radio-button>
 <a-radio-button value="b">Shanghai</a-radio-button>
 <a-radio-button value="c">Beijing</a-radio-button>
 <a-radio-button value="d">Chengdu</a-radio-button>
 </a-radio-group>

 <a-menu theme="dark">
 <a-sub-menu key="sub4">
 <span slot="title"><a-icon type="setting" /><span>Navigation Three</span></span>
 <a-menu-item key="9">Option 9</a-menu-item>
 <a-menu-item key="10">Option 10</a-menu-item>
 <a-menu-item key="11">Option 11</a-menu-item>
 <a-menu-item key="12">Option 12</a-menu-item>
 </a-sub-menu>
 </a-menu>
 <a-pagination :total="50" />

 <a-checkbox-group >
 <a-checkbox value="A">A</a-checkbox>
 <a-checkbox value="B">B</a-checkbox>
 <a-checkbox value="C">C</a-checkbox>
 <a-checkbox value="D">D</a-checkbox>
 <a-checkbox value="E">E</a-checkbox>
 </a-checkbox-group>
 </a-col>
 </a-row>
 </div>
</template>

<script>
// @ is an alias to /src

export default {
 name: 'home',
 components: {},
 data () {
 return {
 color: ''
    }
  },
 methods: {
 click (color) {
 this.color = color
 this.huan()
    },
 huan () {
 window.less
        .modifyVars({
 '@primary-color': this.color,
 '@link-color': this.color,
 '@btn-primary-bg': this.color
        })
        .then(() => {
 console.log('成功')
        })
        .catch(error => {
 alert('失败')
 console.log(error)
        })
    }
  }
}
</script>
### YOLOv11 HWD 技术概述 YOLOv11 HWD一种基于YOLO系列目标检测框架的最新版本,该版本引入了多项技术创新来提升模型性能和效率。具体来说,在架构设计上进行了显著优化[^1]。 #### 卷积层改进 为了提高特征提取能力并减少计算量,YOLOv11 HWD采用了更高效的卷积操作方式。通过引入可变形卷积(Deformable Convolution),使得网络能够自适应调整感受野大小,从而更好地捕捉不同尺度的目标对象特性。 ```python import torch.nn as nn class DeformConv(nn.Module): def __init__(self, inc, outc, kernel_size=3, stride=1, padding=1, bias=False): super(DeformConv, self).__init__() self.conv = nn.Conv2d(inc, outc, kernel_size=kernel_size, stride=stride, padding=padding, bias=bias) def forward(self, x, offset): # 实现可变形卷积的具体逻辑 pass ``` #### 主干网增强 在主干部分,YOLOv11 HWD融合了多种先进的骨干网络结构,如CSPNet、EfficientNet等,并对其进行了针对性修改以适配实时检测需求。这种组合不仅增强了深层特征表达力,还有效降低了参数数量与运算复杂度。 #### 颈部模块创新 Neck作为连接backbone与head的关键组件,在YOLOv11 HWD中得到了特别加强。采用FPN-PAN混合结构的同时加入了动态路由机制,允许信息流根据实际场景灵活分配权重,进一步提升了多尺度物体检测精度。 #### 注意力机制应用 不同于以往简单堆砌Attention Unit的做法,YOLOv11 HWD精心挑选了几类适合于快速推理阶段使用的轻量化注意力单元,比如SE Block、CBAM等,并巧妙地嵌入到整个pipeline当中,实现了速度与准度之间的良好平衡。 #### 检测头升级 最后,在预测头部方面也做出了不少改动。除了常规的分类分支外,新增加了一个专门用于估计边界框质量得分的质量评估子网络,这有助于过滤掉低置信度的结果,进而改善最终输出的效果。
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值