首页 > 其他分享 >vite Ant Design Vue 动态主题

vite Ant Design Vue 动态主题

时间:2022-10-22 17:11:37浏览次数:58  
标签:Vue const Ant reactive colorState vue Design ConfigProvider import

简单记录一下。

官网地址:https://www.antdv.com/docs/vue/customize-theme-cn

antd全局化配置:https://www.antdv.com/components/config-provider-cn

开始没懂怎么去使用,查了资料也没有实现ConfigProvider配置的效果。

整理一下思路,使用ConfigProvider进行配置,不考虑动态的情况下静态配置怎么生效?

配置App.vue

 1 <!-- APP.vue -->
 2 <template>
 3   <a-config-provider>
 4     <router-view />
 5   </a-config-provider>
 6 </template>
 7 <script setup>
 8 import { reactive } from "vue";
 9 import { ConfigProvider } from "ant-design-vue";
10 
11 // 直接官网复制的代码
12 const colorState = reactive({
13   primaryColor: "#25b864",
14   errorColor: "#ff4d4f",
15   warningColor: "#faad14",
16   successColor: "#52c41a",
17   infoColor: "#1890ff",
18 });
19 ConfigProvider.config({
20   theme: colorState,
21 });
22 </script>

HelloWorld.vue:

<template>
  <a-card>
    <a-row justify="center">
      <a-col>
        <input type="color" :value="colorState.primaryColor" @input="e => onColorChange('primaryColor', e)" />
      </a-col>
    </a-row>
    <br />
    <a-row gutter="20" align="middle" justify="center">
      <a-col>
        <a-checkbox v-model:checked="checked">Checkbox</a-checkbox>
      </a-col>
      <a-col>
        <a-button type="primary">Primary</a-button>
      </a-col>
      <a-col>
        <a-button>Default</a-button>
      </a-col>
      <a-col>
        <a-button type="dashed">Dashed</a-button>
      </a-col>
      <a-col>
        <a-button type="text">Text</a-button>
      </a-col>
      <a-col>
        <a-button type="link">Link</a-button>
      </a-col>
      <a-col>
        <a-button type="primary" @click="info">HelloWorld</a-button>
      </a-col>
      <a-col>
        <a-checkable-tag checked>CheckableTag</a-checkable-tag>
      </a-col>
    </a-row>
  </a-card>

</template>
<script setup>
// 引入配置
import {  ConfigProvider } from "ant-design-vue";
import { ref, reactive } from "vue";

const checked = ref(false);

//与app.vue一致
const colorState = reactive({
  primaryColor: "#25b864",
});
const onColorChange = (type, e) => {
  console.log(type, e.target.value, "颜色");
  Object.assign(colorState, {
    [type]: e.target.value,
  });
  ConfigProvider.config({
    theme: colorState,
  });
};

</script>

但是没得效果:

生效:

文档:需要引入替换当前项目引入样式文件为 CSS Variable 版本。

引入:

// main.js
import "ant-design-vue/dist/antd.variable.min.css";

引入后在vite.config.中修改

 1 AntDesignVueResolver({  importStyle: false }) 

刷新: 此时主题就生效了。

 

最后:colorState 参数放进状态管理里面。

 

标签:Vue,const,Ant,reactive,colorState,vue,Design,ConfigProvider,import
From: https://www.cnblogs.com/wq2333/p/16816660.html

相关文章

  • Vue3+TS项目无法识别自动导入提示
    遇到问题在写Vue3+TS项目的时候,经常遇到写完一个新方法后,在组件使用的时候无法自动识别。解决方案Volar:RestartVueServer重新启动Vue服务......
  • 8_vue是如何代理数据的
    在了解了关于js当中的Object.defineProperty()这个方法后,我们继续对vue当中的数据代理做一个基于现在的解析建议观看之前先了解下js当中的Obejct.defineProperty()链接地......
  • 漂浮广告floatingAd Vue版
    朋友找我帮忙写一个vue版的漂浮广告组件原版插件博客地址:http://www.ijquery.cn/?p=1291代码参考的是(jquery版),https://gitee.com/hongweizhiyuan/floatingAd,插件效果演......
  • vue里面echarts的使用
    一、先安装echarts--Handbook-ApacheECharts;二、在min的文件中引入Vue.prototype.$echarts=echarts;import*asechartsfrom'echarts';三、在html里面增加一个d......
  • vue-router
    入门1.前言router路由应为vue是单页应用不会有那么多html让我们跳转所有要使用路由做页面的跳转Vue路由允许我们通过不同的URL访问不同的内容。通过Vue可以实......
  • vue中工作总结
    1.vue中数据向下传递时,无法使用@close方法清除原因:传递的时候需要进行一波深拷贝方法:JSON.parse(JSON.stringify(obj))2.表格选择的时候无法再次点击取消使用elementui的时......
  • Vue 笔记6 模板分离
                   ......
  • Vue3 系统入门与项目实战2022克鲁斯卡尔算法
    ​Vue3系统入门与项目实战2022克鲁斯卡尔算法计算机的记忆金字塔1.局部性原则局部性原则是制定存储系统数据管理策略的理论基础。我们可以从两个维度来理解它:1.时间局......
  • vue3中$attrs的变化与inheritAttrs的使用
    在vue3中的$attrs的变化$listeners已被删除合并到$attrs中。$attrs现在包括class和style属性。也就是说在vue3中$listeners不存在了。vue2中$listeners是单独存在的。......
  • vue.js中实现阻止事件冒泡
    当父子元素中都有点击事件的时候,为了让触发子元素中的事件时,不去触发父元素中的事件,可以在子元素事件中添加stop来阻止事件冒泡。 .stop是阻止冒泡行为,不让当前元素的......