Skip to main content

๐Ÿ‘ฉโ€๐Ÿ’ป element ui plus ๆš—้ป‘ๆจกๅผ

็‰ˆๆœฌโ€‹

  • vue: 3.2.41
  • vite: 3.2.0
  • typescript: 4.6.4
  • element-plus: 2.3.12

ๅฎ‰่ฃโ€‹

ๅ…ˆๅฎ‰่ฃ vueUseโ€‹

vueUse ้กžไผผ react ไธญ็š„ hooks

yarn add @vueuse/core

ๅŠ ๅ…ฅ้–‹้—œโ€‹

ๆ–ผ App.vue

<script setup lang="ts">
import { useDark } from "@vueuse/core";
const isDark = useDark();
</script>

<template>
<div>
<button @click="toggleDark()">
ๆ˜ฏๅฆ็‚บๆš—้ป‘ๆจกๅผ: {{ isDark }}
</button>
</div>
<main>
<router-view />
</main>
</template>

ๅŠ ๅ…ฅ cssโ€‹

ๆ–ผ style.css

html.dark {
/* ่ƒŒๆ™ฏ้ก่‰ฒ */
--af-bg-color: #000000;
}

ๅŠ ๅ…ฅๆทฑ่‰ฒไธป้กŒโ€‹

import { createApp } from "vue";
import { createPinia } from "pinia";
import './style.css'
import 'element-plus/theme-chalk/dark/css-vars.css'
import ElementPlus from 'element-plus'
import router from "./router/index";
import App from "./App.vue";

const app = createApp(App);

app.use(router).use(createPinia()).use(ElementPlus, { size: 'small', zIndex: 3000 }).mount("#app");