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 주제 전환 내용은 저희 이전의 글을 검색하거나 아래의 관련 글을 계속 훑어보십시오. 앞으로 많은 응원 부탁드립니다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
VUE 기반 장치가 PC인지 모바일 포트인지 판단실제 개발 과정에서 자주 발생하는 수요는 현재 웹 페이지에 로그인한 장치가 PC인지 이동인지를 판단하고 PC 측과 모바일 측이 서로 다른 웹 내용을 표시하도록 요구하는 것이다. 그러면 현재 로그인 장치에 대한 판단이...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.