Switch add new prop: true-color & false-color

Switch add new prop: true-color & false-color
This commit is contained in:
mo.duan 2019-09-06 15:11:47 +08:00
parent 6b285b78ed
commit 574a325c45
2 changed files with 21 additions and 1 deletions

View file

@ -32,6 +32,7 @@
<br><br> <br><br>
<i-switch :disabled="disabled"></i-switch> <i-switch :disabled="disabled"></i-switch>
<Button type="primary" @click="disabled = !disabled">Toggle Disabled</Button> <Button type="primary" @click="disabled = !disabled">Toggle Disabled</Button>
<i-switch v-model="switch1" true-color="#13ce66" false-color="#ff4949" />
</div> </div>
</template> </template>
<script> <script>
@ -40,7 +41,8 @@
return { return {
m1: true, m1: true,
disabled: true, disabled: true,
loading: false loading: false,
switch1 : true
} }
}, },
methods: { methods: {

View file

@ -2,6 +2,7 @@
<span <span
tabindex="0" tabindex="0"
:class="wrapClasses" :class="wrapClasses"
:style="wrapStyles"
@click="toggle" @click="toggle"
@keydown.space="toggle" @keydown.space="toggle"
> >
@ -52,6 +53,12 @@
loading: { loading: {
type: Boolean, type: Boolean,
default: false default: false
},
trueColor: {
type: String
},
falseColor: {
type: String
} }
}, },
data () { data () {
@ -71,6 +78,17 @@
} }
]; ];
}, },
wrapStyles () {
let style = {};
if (this.trueColor && this.currentValue === this.trueValue) {
style['border-color'] = this.trueColor;
style['background-color'] = this.trueColor;
} else if (this.falseColor && this.currentValue === this.falseValue) {
style['border-color'] = this.falseColor;
style['background-color'] = this.falseColor;
}
return style;
},
innerClasses () { innerClasses () {
return `${prefixCls}-inner`; return `${prefixCls}-inner`;
} }