vue3全局控制Element plus所有组件的文字大小

项目框架vue-右上角有控制全文的文字大小

实现:

只能控制element组件的文字及输入框等大小变化,如果是自行添加div,text, span之类的控制不了。

配置流程

APP.vue

使用element的provide,包含app

<el-config-provider :locale="locale" :size="size">
<template>
  <el-config-provider :locale="locale" :size="size">
    <!-- 开启水印 -->
    <el-watermark
      v-if="watermarkEnabled"
      :font="{ color: fontColor }"
      :content="defaultSettings.watermarkContent"
      class="wh-full"
    >
      <router-view />
    </el-watermark>
    <!-- 关闭水印 -->
    <router-view v-else />
  </el-config-provider>
</template>

<script setup lang="ts">
import { useAppStore, useSettingsStore } from "@/store";
import defaultSettings from "@/settings";
import { ThemeEnum } from "@/enums/ThemeEnum";

const appStore = useAppStore();
const settingsStore = useSettingsStore();

const locale = computed(() => appStore.locale);
const size = computed(() => appStore.size);
const watermarkEnabled = computed(() => settingsStore.watermarkEnabled);

// 明亮/暗黑主题水印字体颜色适配
const fontColor = computed(() => {
  return settingsStore.theme === ThemeEnum.DARK
    ? "rgba(255, 255, 255, .15)"
    : "rgba(0, 0, 0, .15)";
});
</script>

点击界面的文字大小时,更新全局变量变更size

const appStore = useAppStore();
const size = computed(() => appStore.size);

 useAppStore() 点击按钮时,会调用到的事件

function changeSize(val: string) {
  size.value = val;
}

 切换:操作日记是一个div不会变,表格是el-table,会根据大小变化。

相关推荐

  1. vue3注册全局组件

    2024-03-28 09:38:03       38 阅读
  2. vue3中Element Plus全局组件配置中文两种方案

    2024-03-28 09:38:03       63 阅读
  3. Vue全局组件

    2024-03-28 09:38:03       34 阅读
  4. vue3 学习笔记16 -- elementPlus使用

    2024-03-28 09:38:03       29 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-28 09:38:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-28 09:38:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-28 09:38:03       82 阅读
  4. Python语言-面向对象

    2024-03-28 09:38:03       91 阅读

热门阅读

  1. 知识蒸馏的知识是什么?

    2024-03-28 09:38:03       41 阅读
  2. 每天学习一个Linux命令之date

    2024-03-28 09:38:03       37 阅读
  3. git命令-项目使用

    2024-03-28 09:38:03       43 阅读
  4. webpack.prod.js(webpack生产环境配置文件)

    2024-03-28 09:38:03       43 阅读
  5. Web工程化 (webpack)

    2024-03-28 09:38:03       44 阅读
  6. 数据结构之队列

    2024-03-28 09:38:03       41 阅读
  7. 一个简单的自执行函数--webpack

    2024-03-28 09:38:03       36 阅读
  8. git 代码管理仓库/安装部署

    2024-03-28 09:38:03       43 阅读
  9. Linux | CLI arguments 和 Environment variables 是什么

    2024-03-28 09:38:03       36 阅读