vue自定义switch开关,使用less支持换肤
实际项目用到了,记录一下,也方便以后使用,这样也可以避免为了使用一个switch,引入整个外部web框架;
也可以方便更好的理解是和使用less。
基础代码使用的是网上的,然后自己添加了less换肤,修改了样式。
代码如下:
<template>
<div :class="{'theme-danger':danger,'theme-default':!danger}">
<span class="weui-switch" :class="{'weui-switch-on' : isChecked}" :value="value" @click="toggle"
style="position:relative">
<div v-if="isChecked && direction.length > 0"
style="width:100%;height:100%;position:absolute;padding:0 5px;line-height:20px;color:#FFF;user-select:none">
{{direction[0]}}
</div> <div v-if="!isChecked && direction.length > 0"
style="width:100%;height:100%;position:absolute;padding:0 5px;right:2px;line-height:22px;color:#7A7A7A;text-align:right;user-select:none">
{{direction[1]}}
</div> </span>
</div>
</template> <script>
export default {
name: 'switchComponent',
props: {
value: {
type: Boolean,
default: true
},
//开关文字描述
text: {
type: String,
default: ''
},
//目前定义的一个主题,支持后续自己替换
danger: {
type: Boolean,
default: false
},
},
data() {
return {
isChecked: this.value
}
},
computed: {
direction() {
if (this.text) {
return this.text.split('|')
} else {
return []
}
}
},
watch: {
value(val) {
this.isChecked = val
},
isChecked(val) {
this.$emit('change', val);
}
},
methods: {
toggle() {
this.isChecked = !this.isChecked;
}
}
}
</script> <style scoped lang="less"> /* 公共函数部分 */
.theme(@default-color,@border-color) {
/*将所有的涉及到切换主题的样式全部放在此处*/
.weui-switch {
display: block;
position: relative;
width: 38px;
height: 20px;
border: 1px @border-color;
outline: 0;
border-radius: 15px;
box-sizing: border-box;
background-color: @border-color;
transition: background-color 0.1s, border 0.1s;
cursor: pointer;
box-shadow: 0 1px 1px @default-color;
} .weui-switch:before {
content: " ";
position: absolute;
top: 1px;
left: 1px;
width: 36px;
height: 19px;
border-radius: 15px;
background: rgba(18, 39, 66);
transition: transform 0.35s cubic-bezier(0.45, 1, 0.4, 1);
} .weui-switch:after {
content: " ";
position: absolute;
top: 3px;
left: 3px;
width: 15px;
height: 15px;
border-radius: 10px;
background-color: @default-color;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
transition: transform 0.35s cubic-bezier(0.4, 0.4, 0.25, 1.35);
} .weui-switch-on:after {
background: #FFFFFF;
} .weui-switch-on {
border-color: #6F6F6F;
background-color: @default-color;
} .weui-switch-on:before {
border-color: @border-color;
background-color: @default-color;
} .weui-switch-on:after {
transform: translateX(17px);
}
} /*不同主题传不同的变量*/
.theme-default {
@default-color: rgba(34, 190, 255, 1);
@border-color: rgba(34, 190, 255, 1);
.theme(@default-color, @border-color);
} .theme-danger {
@default-color: rgba(235, 97, 0, 1);
@border-color: #EB6100;
.theme(@default-color, @border-color);
} </style>
vue自定义switch开关,使用less支持换肤的更多相关文章
- 自定义switch开关
自定义一个switch开关 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- vue elementui switch开关控件的使用
<el-switch @change="test" on-value="1" off-value="0" v-model=" ...
- vue+less换肤,主题切换方案
新的项目对于客户自定义要求很高,然后换肤是其中一个很小的模块,经过了一段时间的摸索,看了许多文章,找到了几种方案. https://www.cnblogs.com/leiting/p/11203383 ...
- Android应用换肤总结
换肤,我们都很熟悉,像XP的主题,塞班的主题.看过国外的一些技术博客,就会发现国内和国外对软件的,或者说移动开发的软件的需求的不同.国外用户注重社交.邮件等功能,国内用户则重视音乐.小说.皮肤等功能, ...
- Android App插件式换肤实现方案
背景 目前很多app都具有换肤功能,用户可以根据需要切换不同的皮肤,为使我们的App支持换肤功能,给用户提供更好的体验,在这里对换肤原理进行研究总结,并选择一个合适的换肤解决方案. 换肤介绍 App换 ...
- Android QMUI实战:实现APP换肤功能,并自动适配手机深色模式
Android换肤功能已不是什么新鲜事了,市面上有很多第三方的换肤库和实现方案. 之所以选择腾讯的QMUI库来演示APP的换肤功能,主要原因: 1.换肤功能的实现过程较简单.容易理解: 2.能轻松适配 ...
- 一文读懂HarmonyOS服务卡片怎么换肤
作者:zhenyu,华为软件开发工程师 关注HarmonyOS的小伙伴肯定对服务卡片已经很熟悉了.服务卡片(也简称为"卡片")是FA(FeatureAbility,元服务)的一种界 ...
- 在WPF中创建可换肤的用户界面
原文:在WPF中创建可换肤的用户界面 在WPF中创建可换肤的用户界面. ...
- ASP.NET MVC扩展自定义视图引擎支持多模板&动态换肤skins机制
ASP.NET mvc的razor视图引擎是一个非常好的.NET MVC框架内置的视图引擎.一般情况我们使用.NET MVC框架为我们提供的这个Razor视图引擎就足够了.但是有时我们想在我们的项目支 ...
随机推荐
- 通过CSS让图片变的清楚
image { width: 100%; height: 100%; border-radius: 10upx; //让图片变清楚 image-rendering: -moz-crisp-edges; ...
- swiper使用
swiper使用 初始化 var mySwiper = new Swiper ('容器区域类', { // 存放swiper属性 }) 属性 基本属性: 1.initialSlide 设定初始化时sl ...
- python常用标准库(时间模块 time和datetime)
常用的标准库 time时间模块 import time time -- 获取本地时间戳 时间戳又被称之为是Unix时间戳,原本是在Unix系统中的计时工具. 它的含义是从1970年1月1日(UTC/G ...
- 『忘了再学』Shell基础 — 22、主要的环境变量配置文件说明
目录 1.source命令 2.Linux系统中环境变量配置文件 (1)登录时生效的环境变量配置文件 (2)/etc/profile环境变量配置文件 (3)/etc/profile.d/*.sh环境变 ...
- 测试open
// 此处,返回的 undefined 是 JS 中的一个值 return undefined } // 这种写法是明确指定函数返回值类型为 void,与上面不指定返回值类型相同 const add ...
- Docker的网络
概述 docker使用Linux桥接网卡,在宿主机虚拟一个docker容器网桥(docker0),docker启动一个容器时会根 据docker网桥的网段分配给容器一个IP地址,称为Container ...
- 关于Vue在面试中常常被提到的几点(持续更新……)
1.Vue项目中为什么要在列表组件中写key,作用是什么? 我们在业务组件中,会经常使用循环列表,当时用v-for命令时,会在后面写上:key,那么为什么建议写呢? key的作用是更新组件时判断两个节 ...
- 安装ImageMagick7.1库以及php的Imagick扩展
由于ImageMagick7以下不支持heic等图片格式,所以重新安装了ImageMagick7.1版本支持heic格式,并写此文章记录一下. 如果安装过程中遇到一些未知的错误,https://ima ...
- SAP Picture Control(图片加载)
Screen display 效果 源代码 program sap_picture_demo. set screen 200. TYPE-POOLS cndp. ******************* ...
- $.fn解析
$.fn是指jquery的命名空间,加上fn上的方法及属性,会对jquery实例每一个有效. 如扩展$.fn.abc(),即$.fn.abc()是对jquery扩展了一个abc方法,那么后面你的每一个 ...