Created
June 14, 2017 07:59
-
-
Save Graniron/5dd4d21dc075969c1f3745b2658cd8bc to your computer and use it in GitHub Desktop.
Switcher component for vue.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<app-switch v-model="dataSwitch"></app-switch> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<div id="on" @click="switched(true)" :class="{active: value}">On</div> | |
<div id="off" @click="switched(false)" :class="{active: !value}">Off</div> | |
</div> | |
</template> | |
<script> | |
export default { | |
props: ['value'], | |
methods: { | |
switched(isOn) { | |
this.$emit('input', isOn) | |
} | |
} | |
} | |
</script> | |
<style scoped> | |
#on, #off { | |
width: 40px; | |
height: 20px; | |
background-color: lightgray; | |
padding: 2px; | |
display: inline-block; | |
margin: 10px -2px; | |
box-sizing: content-box; | |
cursor: pointer; | |
text-align: center; | |
} | |
#on:hover, #on.active { | |
background-color: lightgreen; | |
} | |
#off:hover, #off.active { | |
background-color: lightcoral; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment