CheckBoxValue.vue 997 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <a-checkbox
  3. v-model:checked="checked"
  4. v-bind="checkboxProps"
  5. >{{text}}</a-checkbox>
  6. </template>
  7. <script lang="ts">
  8. import { defineComponent, type PropType } from "vue";
  9. import type { CheckboxProps } from "ant-design-vue";
  10. export default defineComponent({
  11. props: {
  12. checkboxProps: {
  13. type: Object as PropType<CheckboxProps>,
  14. default: null,
  15. },
  16. text: {
  17. type: String,
  18. default: '',
  19. },
  20. checkedValue: {
  21. default: true,
  22. },
  23. uncheckedValue: {
  24. default: false,
  25. },
  26. value: {
  27. },
  28. },
  29. emits: [ 'update:value' ],
  30. watch: {
  31. checked(v) {
  32. this.$emit('update:value', v ? this.checkedValue : this.uncheckedValue);
  33. },
  34. value(v) {
  35. const checked = v === this.checkedValue;
  36. if (this.checked != checked)
  37. this.checked = checked;
  38. },
  39. },
  40. data() {
  41. return {
  42. checked: false,
  43. }
  44. },
  45. mounted() {
  46. this.checked = this.value === this.checkedValue;
  47. },
  48. });
  49. </script>