Switch.vue 1.2 KB

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