VUE 프로젝트에서 주제 전환을 위한 다양한 방법

4350 단어 VUE주제 전환
짙은 색 테마와 연한 색 테마를 전환하는 효과가 필요합니다.
방법
이 방법도 가장 간단하고 지루하다.

<!--   -->
<template>
  class , class 
 <div :class="className">
 <div class="switch" v-on:click="chang()">
  {{ className == "box" ? " " : " " }}
 </div>
 </div>
</template>
<script>
export default {
 name: "Centre",
 data() {
 return {
  className: "box"
 };
 },
 methods: {
 //  class
 chang() {
  this.className === "box"
  ? (this.className = "boxs") 
  : (this.className = "box");
 }
 },
};
</script>
<style lang="scss">
 class box  witch css
@import "./style/witch.scss";
 class boxs  black css
@import "./style/black.scss";
.switch {
 position: fixed;
 top: 4px;
 right: 10px;
 z-index: 50;
 width: 60px;
 height: 60px;
 background: #fff;
 line-height: 60px;
 border-radius: 20%;
}
</style>
모든 css 파일의 스타일은 대체적으로 같지만 가장 바깥쪽의 부급은 다르다. 각각.box 및.boxs
방법 2 scss 동적 전환 변수
저는 두 개의 메인 파일로 나눠서 만들었어요.
_variable.scss 변수 관리 파일
var () css3에서 제시한 성명 스타일 변수를 위한 방법
var (속성 이름, 속성 값) 속성 값이 문자열일 수 없음 주의

//  
$bgColor:var(--backgroundColor,rgb(255,255,255));
$fontColor:var(--fonntColor,rgb(0,0,0));
$bgmColor:var(--backgroundMColor,rgb(238,238,238));
$tableColor:var(--tableColor,rgb(218,218,218));
$borderColor:var(--borderColor,rgb(238,238,238));
$tablesColor:var(--tablesColor,rgb(255,255,255));
$inputColor:var(--inputColor,rgb(255,255,255))
생성된_variable.scss 파일 vue에 있습니다.config.js는 구성 요소에 도입하지 않은 전역적인 설정을 진행했습니다

 css: {
 loaderOptions: {
  //  
  sass: {
  prependData: `@import "./src/styles/_variable.scss";`,
  },
 },
 },
2.publicStyle.js
이 방법은 var가 정의한 변수를 수정할 수 있다
document.getElementsByTagName("body")[0].style.setProperty(등록 정보 이름, 대체 등록 정보 값 f);

//  
const cut = (cutcheack) => {
 document.getElementsByTagName("body")[0].style.setProperty("--backgroundColor", cutcheack ? "#121212" : "#fff");
 document.getElementsByTagName("body")[0].style.setProperty("--fonntColor", cutcheack ? "#cecece" : "#333");
 document.getElementsByTagName("body")[0].style.setProperty("--backgroundMColor", cutcheack ? "#333" : "#eee");
 document.getElementsByTagName("body")[0].style.setProperty("--tableColor", cutcheack ? "#000" : "#d8d8d8");
 document.getElementsByTagName("body")[0].style.setProperty("--tablesColor", cutcheack ? "#222" : "#fff");
 document.getElementsByTagName("body")[0].style.setProperty("--inputColor", cutcheack ? "#666" : "#fff");
 document.getElementsByTagName("body")[0].style.setProperty("--borderColor", cutcheack ? "#666" : "#fff");
};
export default cut;
어셈블리에서 사용

<!--   -->
<template>
<div class='home'>
  <el-switch v-model="cutcheack" active-color="#333" inactive-color="#13ce66" active-text=" " @change="switchs"></el-switch>
</div>
</template>
<script>
import cut from "../../utils/publicStyle.js";
export default {
 name: "Home",
 data() {
 return {
  cutcheack: false, // 
 };
 },
 methods: {
 //  
 //  
 switchs() {
  cut(this.cutcheack);
 },
 },
};
</script>
<style lang='scss' scope>
.home {
 height: 100%;
 width: 100%;
	background:$bgColor;
 .el-container {
  height: 100%;
  color:$fontColor;
 }
}
</style>
VUE 프로젝트의 주제 전환에 관한 이 글은 여기까지 소개합니다. 더 많은 VUE 주제 전환 내용은 저희 이전의 글을 검색하거나 아래의 관련 글을 계속 훑어보십시오. 앞으로 많은 응원 부탁드립니다!

좋은 웹페이지 즐겨찾기