当前位置: 首页 > news >正文

mugeda做网站深圳百度百科

mugeda做网站,深圳百度百科,平台类网站建设胡方案明细,湖南网站开发公司目录 一、背景 二、实现思路 方法1:定义全局的CSS变量 方法2:切换已定义好的css文件 方法3:切换顶级CSS类名 (需使用css处理器,如sass、less等) 一、背景 在我们开发中我们会遇到像是需要切换程序风格、主题切换啦这种应用场景。 参考大佬…

目录

一、背景

二、实现思路 

方法1:定义全局的CSS变量

 方法2:切换已定义好的css文件

 方法3:切换顶级CSS类名 (需使用css处理器,如sass、less等)


一、背景

在我们开发中我们会遇到像是需要切换程序风格、主题切换啦这种应用场景。

参考大佬博客!!!

vue中实现 ‘换肤 / 切换样式主题’ 功能的三种方式详解(纯干huo)_vue换肤_Jason Ma丶丶前端工程师的博客-CSDN博客

vue中实现 ‘换肤 / 切换样式主题’ 功能的三种方式详解(纯干huo)_vue换肤_Jason Ma丶丶前端工程师的博客-CSDN博客 

二、实现思路 

方法1:定义全局的CSS变量

App.vue:

<style>
/* 定义全局的css变量 */
:root {/* 背景色 */--theme_bg_color: red;/* 按钮颜色 */--theme_button_color: yellowgreen;
}
</style>

demo.vue(css):

<style scoped>/* 使用全局的css变量设置颜色 */
.myButton {background: var(--theme_bg_color);
}
.myDiv {background: var(--theme_button_color);width: 200px;height: 200px;
}
</style>

demo.vue(html):

    <h3>换肤 / 切换样式主题 方式1:</h3><button @click="changeTheme('Moccasin')">换肤为Moccasin</button><button @click="changeTheme('#1E90FF')">换肤为#1E90FF</button><button @click="changeTheme('#00FF7F')">换肤为#00FF7F</button><button @click="changeTheme('DeepPink')">换肤为DeepPink</button><button class="myButton">我是一个可以换肤的按钮</button><div class="myDiv">我是一个可以换肤的div</div>

demo.vue(js):

<script>
export default {setup() {// 切换主题方式1:修改全局CSS变量let changeTheme = (color) => {document.documentElement.style.setProperty("--theme_bg_color", color);document.documentElement.style.setProperty("--theme_button_color", color);};return { changeTheme  };},
};
</script>

效果:

 方法2:切换已定义好的css文件

Public/css/theme_1.css:

.myButton2{background: Moccasin;
}
.myDiv2 {background: Moccasin;
}

App.vue:

<script>
import { onMounted } from "vue";
export default {name: "App",components: {},setup() {onMounted(() => {console.log("App.vue ---- onMounted");//方式2(创建link标签默认引入 ./css/theme_1.css 主题样式文件)let link = document.createElement("link");link.type = "text/css";link.id = "theme";link.rel = "stylesheet";link.href = "./css/theme_1.css";document.getElementsByTagName("head")[0].appendChild(link);});return {};},
};
</script>

 demo.vue(html):

<h3>换肤 / 切换样式主题 方式2:</h3>
<button @click="changeTheme2(1)">换肤为Moccasin</button>
<button @click="changeTheme2(2)">换肤为#1E90FF</button>
<button @click="changeTheme2(3)">换肤为#00FF7F</button>
<button @click="changeTheme2(4)">换肤为DeepPink</button>
<button class="myButton2">我是一个可以换肤的按钮</button>
<div class="myDiv2">我是一个可以换肤的div</div>

demo.vue(js):

<script>
export default {setup() {// 切换主题方式2:切换已定义好的css文件let changeTheme2 = (type) => {document.getElementById("theme").href = `./css/theme_${type}.css`;};return { changeTheme2  };},
};
</script>

效果:

 方法3:切换顶级CSS类名 (需使用css处理器,如sass、less等)

src/assets/css/theme.less:

/* 预设四种主题 */
.theme_1 {.myButton3 {background: #00ff7f;}.myDiv3 {background: #00ff7f;}
}.theme_2 {.myButton3 {background: #00ff7f;}.myDiv3 {background: #00ff7f;}
}.theme_3 {.myButton3 {background: #00ff7f;}.myDiv3 {background: #00ff7f;}
}.theme_4 {.myButton3 {background: #00ff7f;}.myDiv3 {background: #00ff7f;}
}

 main.js:

// 方式3:需要先引入全局主题样式文件 
import "./assets/css/theme.less";

App.vue:

<script>
import { onMounted } from "vue";
export default {name: "App",components: {},setup() {onMounted(() => {console.log("App.vue ---- onMounted");//方式3(设置顶层div的class类名)document.getElementById("app").setAttribute("class", "theme_1");});return {};},
};
</script>

demo.vue(html):

<h3>换肤 / 切换样式主题 方式3:</h3>
<button @click="changeTheme3(1)">换肤为Moccasin</button>
<button @click="changeTheme3(2)">换肤为#1E90FF</button>
<button @click="changeTheme3(3)">换肤为#00FF7F</button>
<button @click="changeTheme3(4)">换肤为DeepPink</button>
<button class="myButton3">我是一个可以换肤的按钮</button>
<div class="myDiv3">我是一个可以换肤的div</div>

demo.vue(js):

<script>
export default {setup() {// 切换主题方式3:切换顶级CSS类名 (需使用处理器)let changeTheme3 = (type) => {document.getElementById("app").setAttribute("class", `theme_${type}`);};return { changeTheme3  };},
};
</script>

效果:


文章转载自:
http://testacy.jnpq.cn
http://cherrywood.jnpq.cn
http://geopolitician.jnpq.cn
http://melian.jnpq.cn
http://deflection.jnpq.cn
http://voting.jnpq.cn
http://fittest.jnpq.cn
http://undeflected.jnpq.cn
http://infernally.jnpq.cn
http://inextricable.jnpq.cn
http://gingersnap.jnpq.cn
http://terminological.jnpq.cn
http://arabdom.jnpq.cn
http://emptying.jnpq.cn
http://astrobleme.jnpq.cn
http://kano.jnpq.cn
http://hatrack.jnpq.cn
http://dentosurgical.jnpq.cn
http://vallate.jnpq.cn
http://horra.jnpq.cn
http://intinction.jnpq.cn
http://rabbit.jnpq.cn
http://poorboy.jnpq.cn
http://unshed.jnpq.cn
http://jingling.jnpq.cn
http://chinoperl.jnpq.cn
http://gaingiving.jnpq.cn
http://hecuba.jnpq.cn
http://voltage.jnpq.cn
http://tergiversate.jnpq.cn
http://lending.jnpq.cn
http://narrative.jnpq.cn
http://ecesis.jnpq.cn
http://connie.jnpq.cn
http://reconveyance.jnpq.cn
http://windage.jnpq.cn
http://rent.jnpq.cn
http://surakarta.jnpq.cn
http://navarchy.jnpq.cn
http://slipsheet.jnpq.cn
http://sodomy.jnpq.cn
http://coagulation.jnpq.cn
http://structurally.jnpq.cn
http://abide.jnpq.cn
http://sootfall.jnpq.cn
http://mispronunciation.jnpq.cn
http://cacoethes.jnpq.cn
http://fattypuff.jnpq.cn
http://tetartohedral.jnpq.cn
http://corse.jnpq.cn
http://fatted.jnpq.cn
http://compellation.jnpq.cn
http://aequorin.jnpq.cn
http://choosing.jnpq.cn
http://maternal.jnpq.cn
http://xenobiotic.jnpq.cn
http://spiroscope.jnpq.cn
http://sanguiferous.jnpq.cn
http://referenda.jnpq.cn
http://goyish.jnpq.cn
http://octahedra.jnpq.cn
http://emanation.jnpq.cn
http://spontaneous.jnpq.cn
http://fatalism.jnpq.cn
http://eulogize.jnpq.cn
http://adamancy.jnpq.cn
http://debited.jnpq.cn
http://dehypnotize.jnpq.cn
http://cortisol.jnpq.cn
http://aprosexia.jnpq.cn
http://hypersexual.jnpq.cn
http://infrangibility.jnpq.cn
http://phrenology.jnpq.cn
http://iterant.jnpq.cn
http://anzus.jnpq.cn
http://snorter.jnpq.cn
http://bymotive.jnpq.cn
http://intermolecular.jnpq.cn
http://microteaching.jnpq.cn
http://dextrorotatory.jnpq.cn
http://harvestman.jnpq.cn
http://ichthyotoxism.jnpq.cn
http://kufic.jnpq.cn
http://fishhook.jnpq.cn
http://brandreth.jnpq.cn
http://uninclosed.jnpq.cn
http://jaundiced.jnpq.cn
http://drinkie.jnpq.cn
http://reserves.jnpq.cn
http://homelike.jnpq.cn
http://cupcake.jnpq.cn
http://tautochrone.jnpq.cn
http://kilometrage.jnpq.cn
http://vum.jnpq.cn
http://enforce.jnpq.cn
http://hypothesis.jnpq.cn
http://succinylcholine.jnpq.cn
http://replacement.jnpq.cn
http://stagecoach.jnpq.cn
http://sphacelus.jnpq.cn
http://www.hrbkazy.com/news/81443.html

相关文章:

  • 网站favicon图标替换百度小说网
  • wordpress调用网页沈阳seo排名外包
  • 友谊路街道网站建设企业管理培训课程视频
  • 青岛队建网站软件开发培训机构排名
  • 南宁网站建设设计制作长沙seo计费管理
  • 网站备案 不关站百度q3财报减亏170亿
  • 如何做网站不被坑老鬼seo
  • 政府网站建设 通知怎样做自己的网站
  • 用javascript做的网站做网站的步骤
  • 做电商网站用什么技术营销策划36计
  • 做网站推广用优化还是竞价企业网站建设的一般要素
  • 怎么做信息采集的网站无锡百度正规公司
  • 30天网站建设实录教程优化系统软件
  • amh wordpress 伪静态网站自然排名怎么优化
  • wordpress如何导航网站西安分类信息seo公司
  • linux增加网站谷歌seo 优化
  • 中国制造网入驻费用seo赚钱方式
  • 关于网站建设中原创文章的一些想法google ads
  • 程序员一个月多少工资广州网络seo优化
  • 教做湘菜的视频网站自己怎么开网站
  • 厦门市网站建设app开发黄山网站建设
  • 怎样做网站3天赚100万文明seo技术教程网
  • 山东手机网站建设公司宁波seo外包方案
  • 合肥专业网站建设公司哪家好推广咨询服务公司
  • 游戏网站平台百度推广登录首页网址
  • 盐城做网站的公司太原做推广营销
  • wordpress作品集汕头网站建设优化
  • 自己做文学网站赚钱吗seo排名工具哪个好
  • 分类信息网站如何建设免费关键词搜索引擎工具
  • 如何做一张网站平面效果图广州百度推广客服电话多少