|
@@ -7,6 +7,8 @@
|
|
|
@change="handleChange"
|
|
|
v-model="_value"
|
|
|
:name="name"
|
|
|
+ :true-value="onValue"
|
|
|
+ :false-value="offValue"
|
|
|
:disabled="disabled">
|
|
|
<span class="el-switch__core" ref="core" :style="{ 'width': coreWidth + 'px' }">
|
|
|
<span class="el-switch__button" :style="{ transform }"></span>
|
|
@@ -14,7 +16,7 @@
|
|
|
<transition name="label-fade">
|
|
|
<div
|
|
|
class="el-switch__label el-switch__label--left"
|
|
|
- v-show="value"
|
|
|
+ v-show="value === onValue"
|
|
|
:style="{ 'width': coreWidth + 'px' }">
|
|
|
<i :class="[onIconClass]" v-if="onIconClass"></i>
|
|
|
<span v-if="!onIconClass && onText">{{ onText }}</span>
|
|
@@ -23,7 +25,7 @@
|
|
|
<transition name="label-fade">
|
|
|
<div
|
|
|
class="el-switch__label el-switch__label--right"
|
|
|
- v-show="!value"
|
|
|
+ v-show="value === offValue"
|
|
|
:style="{ 'width': coreWidth + 'px' }">
|
|
|
<i :class="[offIconClass]" v-if="offIconClass"></i>
|
|
|
<span v-if="!offIconClass && offText">{{ offText }}</span>
|
|
@@ -37,7 +39,7 @@
|
|
|
name: 'ElSwitch',
|
|
|
props: {
|
|
|
value: {
|
|
|
- type: Boolean,
|
|
|
+ type: [Boolean, String],
|
|
|
default: true
|
|
|
},
|
|
|
disabled: {
|
|
@@ -72,6 +74,14 @@
|
|
|
type: String,
|
|
|
default: ''
|
|
|
},
|
|
|
+ onValue: {
|
|
|
+ type: [Boolean, String],
|
|
|
+ default: true
|
|
|
+ },
|
|
|
+ offValue: {
|
|
|
+ type: [Boolean, String],
|
|
|
+ default: false
|
|
|
+ },
|
|
|
name: {
|
|
|
type: String,
|
|
|
default: ''
|
|
@@ -82,6 +92,11 @@
|
|
|
coreWidth: this.width
|
|
|
};
|
|
|
},
|
|
|
+ created() {
|
|
|
+ if (!~[this.onValue, this.offValue].indexOf(this.value)) {
|
|
|
+ this.$emit('input', this.onValue);
|
|
|
+ }
|
|
|
+ },
|
|
|
computed: {
|
|
|
hasText() {
|
|
|
/* istanbul ignore next */
|
|
@@ -96,7 +111,7 @@
|
|
|
}
|
|
|
},
|
|
|
transform() {
|
|
|
- return this.value ? `translate(${ this.coreWidth - 20 }px, 2px)` : 'translate(2px, 2px)';
|
|
|
+ return this.value === this.onValue ? `translate(${ this.coreWidth - 20 }px, 2px)` : 'translate(2px, 2px)';
|
|
|
}
|
|
|
},
|
|
|
watch: {
|
|
@@ -111,7 +126,7 @@
|
|
|
this.$emit('change', event.currentTarget.checked);
|
|
|
},
|
|
|
setBackgroundColor() {
|
|
|
- let newColor = this.value ? this.onColor : this.offColor;
|
|
|
+ let newColor = this.value === this.onValue ? this.onColor : this.offColor;
|
|
|
this.$refs.core.style.borderColor = newColor;
|
|
|
this.$refs.core.style.backgroundColor = newColor;
|
|
|
}
|