Checkbox.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <template>
  2. <div class="wrap">
  3. <Checkbox
  4. class="checkbox"
  5. :mode="mode"
  6. :value="value"
  7. :options="options"
  8. @change="onChange"
  9. @mouseenter="onMouseenter"
  10. @mouseleave="onMouseleave"
  11. />
  12. <span>{{ reactData.tip }}</span>
  13. </div>
  14. </template>
  15. <script lang="ts">
  16. import { Checkbox } from 'ant-design-vue';
  17. import { defineComponent, reactive, toRefs } from 'vue';
  18. const props = {
  19. value: { type: Array, default: [] },
  20. tip: { type: String, default: '' },
  21. mode: { type: String, default: '' },
  22. options: { type: Array, default: [] },
  23. };
  24. export default defineComponent({
  25. components: { Checkbox: Checkbox.Group },
  26. props,
  27. emits: ['change'],
  28. setup(props, { emit }) {
  29. const reactData = reactive({
  30. tip: '',
  31. });
  32. function onMouseenter() {
  33. reactData.tip = props.tip;
  34. }
  35. function onMouseleave() {
  36. reactData.tip = '';
  37. }
  38. function onChange(val) {
  39. emit('change', val);
  40. }
  41. return {
  42. onMouseenter,
  43. onMouseleave,
  44. onChange,
  45. reactData,
  46. ...toRefs(props),
  47. };
  48. },
  49. });
  50. </script>
  51. <style scoped>
  52. .wrap {
  53. display: flex;
  54. }
  55. .checkbox {
  56. width: 65%;
  57. margin-right: 10px;
  58. }
  59. span {
  60. font-size: 13px;
  61. color: gray;
  62. }
  63. </style>