1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<template>
<div class="app-switch">
<el-switch v-model="curValue" :disabled ="disabled"></el-switch><span v-if="isShowText">{{text}}</span>
</div>
</template>
<script lang="ts">
import { Vue, Component, Prop, Model } from 'vue-property-decorator';
@Component({})
export default class AppSwitch extends Vue {
/**
* checked选中状态
*
* @type {boolean}
* @memberof Appswitch
*/
@Prop() public value?: any;
/**
* checked显示文本
*
* @type {boolean}
* @memberof Appswitch
*/
public text:string = "";
/**
* 是否显示文本
*
* @type {boolean}
* @memberof Appswitch
*/
@Prop() public isShowText?: boolean;
get curValue(){
return this.value == 1 ? true:false;
}
set curValue(value:any){
let emitValue = value == true ? 1:0;
this.$emit('change',emitValue);
this.valueChange(value);
}
/**
* 禁用
*
* @type {boolean}
* @memberof Appswitch
*/
@Prop() public disabled?: boolean;
/**
* 生命周期
*
* @memberof Appswitch
*/
mounted(){
this.valueChange(this.curValue);
}
/**
* 文本更新
*
* @memberof Appswitch
*/
public valueChange(value:boolean) {
if(value){
this.text="是"
}else{
this.text="否"
}
}
}
</script>
<style lang='less'>
@import './app-switch.less';
</style>