zxl
17 小时以前 172933f098017bc4c4f57dcda0d490ea12bb13bb
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
<template lang="html">
  <label :class="`${prefixCls}-wrapper`">
    <span :class="checkboxClass">
      <span
        :class="`${prefixCls}__inner`"
        @click="toggle"></span>
    </span>
  </label>
</template>
 
<script>
  export default {
    name: 'zk-checkbox',
    props: {
      value: {
        type: Boolean,
        default: false,
      },
      disabled: {
        type: Boolean,
        default: false,
      },
      indeterminate: {
        type: Boolean,
        default: false,
      },
    },
    data() {
      return {
        prefixCls: 'zk-checkbox',
      };
    },
    computed: {
      checkboxClass() {
        return [
          `${this.prefixCls}`,
          {
            [`${this.prefixCls}--disabled`]: this.disabled,
            [`${this.prefixCls}--checked`]: this.value,
            [`${this.prefixCls}--indeterminate`]: this.indeterminate,
          },
        ];
      },
    },
    methods: {
      toggle() {
        if (this.disabled) {
          return false;
        }
        const value = !this.value;
        this.$emit('input', value);
        return this.$emit('on-change', value);
      },
    },
  };
</script>
 
<style lang="less" scoped src="./Checkbox.less"></style>