Skip to content

Instantly share code, notes, and snippets.

@Graniron
Created June 14, 2017 07:59
Show Gist options
  • Save Graniron/5dd4d21dc075969c1f3745b2658cd8bc to your computer and use it in GitHub Desktop.
Save Graniron/5dd4d21dc075969c1f3745b2658cd8bc to your computer and use it in GitHub Desktop.
Switcher component for vue.js
<div>
<app-switch v-model="dataSwitch"></app-switch>
</div>
<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