CheckBoxToInt.vue 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <a-checkbox
  3. :checked="checked"
  4. @update:checked="(v: boolean) => $emit('update:value', v)"
  5. :disabled="disabled"
  6. >
  7. <slot>{{text}}</slot>
  8. </a-checkbox>
  9. </template>
  10. <script lang="ts">
  11. import { defineComponent } from "vue";
  12. export default defineComponent({
  13. name: "CheckBoxToInt",
  14. data() {
  15. return {
  16. checked: false
  17. }
  18. },
  19. emits: [ 'update:value' ],
  20. props: {
  21. checkedValue: {
  22. type: Number,
  23. default: 1
  24. },
  25. uncheckedValue: {
  26. type: Number,
  27. default: 0
  28. },
  29. disabled: {
  30. type: Boolean,
  31. default: false
  32. },
  33. text: {
  34. type: String,
  35. default: '启用',
  36. },
  37. value: {
  38. default: null,
  39. }
  40. },
  41. mounted: function() {
  42. this.loadChecked();
  43. },
  44. watch: {
  45. value() { this.loadChecked(); },
  46. checked() { this.$emit('update:value', this.checked ? this.checkedValue : this.uncheckedValue) }
  47. },
  48. methods: {
  49. loadChecked() {
  50. this.checked = this.value == this.checkedValue;
  51. }
  52. }
  53. });
  54. </script>