前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Vue 动态换肤

Vue 动态换肤

作者头像
我不是费圆
发布2022-10-28 15:32:31
3080
发布2022-10-28 15:32:31
举报
文章被收录于专栏:鲸鱼动画鲸鱼动画

效果如图:

源代码:

代码语言:javascript
复制
<template>
  <div :class="[`son${temp}`]" class="demo3">
    这是四点零八分的北京<br/>
    一片手的海浪翻动<br/>
    这是四点零八分的北京<br/>
    一声雄伟的汽笛长鸣<br/>
    北京车站高大的建筑<br/>
    突然一阵剧烈地抖动<br/>
    我双眼吃惊地望着窗外<br/>
    不知发生了什么事情
    <div class="footer">
      <div v-for="(i,d) in 4" :key="d" @click="temp = i" :class="[`son${temp}`]" class="button">皮肤{{i}}</div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return { 
      temp: 1, // 皮肤参数
    }
  }
}
</script>
<style lang="scss" scoped>
.footer {
  position: fixed; 
  left: 10vw;
  bottom: 10vh;
  display: flex;
  .button {
    width: 80px;
    height: 40px;
    margin-right: 20px;
    border-radius: 6px;
  }
}
.son1 {
  font-family: 华文新魏;
  font-size: 22px;
  line-height: 2;
  background-image: linear-gradient(35deg, #f99 50%, #99f 100%);
}
.son2 {
  font-family: 方正舒体;
  font-size: 26px;
  line-height: 2;
  background-image: linear-gradient(-60deg, rgb(168, 135, 135) 50%, rgb(122, 122, 156) 100%);
}
.son3 {
  font-family: 隶书;
  font-size: 20px;
  line-height: 2;
  background-image: linear-gradient(135deg, rgb(181, 196, 132) 50%, rgb(78, 78, 173) 100%);
}
.son4 {
  font-family: 仿宋;
  font-size: 26px;
  line-height: 2;
  background-image: linear-gradient(60deg, rgb(214, 232, 157) 50%, rgb(149, 170, 134) 100%);
}
.demo3 {
  width: 100%;
  height: 100vh;
  padding: 20px;
}
</style>

设计思路: 规划几套样式,通过动态class 或 scss 混入 @include 等方式进行赋值,给最外层的父元素添加全局样式。涉及到跨页面操作,可以将class转化为JSON字符串存在storage 或vuex 里,或者封装进公用组件,把每个页面不同的内容以插槽的形式插入。 其它应用场景如:天地图自定义覆盖物,轮播图自定义指示点 相关图片如下:

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022-10-10,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档