Skip to content

Commit

Permalink
Refactoring switch internal value
Browse files Browse the repository at this point in the history
  • Loading branch information
jtommy committed Nov 14, 2018
1 parent b8c103d commit 1a9ffa6
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/components/switch/Switch.vue
Expand Up @@ -11,7 +11,7 @@
@mouseout="isMouseDown = false"
@blur="isMouseDown = false">
<input
v-model="newValue"
v-model="computedValue"
type="checkbox"
@click.stop
:disabled="disabled"
Expand Down Expand Up @@ -49,18 +49,23 @@
isMouseDown: false
}
},
computed: {
computedValue: {
get() {
return this.newValue
},
set(value) {
this.newValue = value
this.$emit('input', value)
}
}
},
watch: {
/**
* When v-model change, set internal value.
*/
value(value) {
this.newValue = value
},
/**
* Emit input event to update the user v-model.
*/
newValue(value) {
this.$emit('input', value)
}
}
}
Expand Down

0 comments on commit 1a9ffa6

Please sign in to comment.