btnTxt.vue 740 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <template>
  2. <ezyActiveVue class="ezy-btn-active keyboard-button"
  3. :class="{active: btnStatus}"
  4. @touchstart="handleTouchStart"
  5. @touchend="handleTouchEnd">
  6. <slot></slot>
  7. </ezyActiveVue>
  8. </template>
  9. <script setup>
  10. import ezyActiveVue from "@/components/ezyActive/ezyActive.vue";
  11. import {
  12. ref
  13. } from "vue"
  14. // 按下状态
  15. const btnStatus = ref(false)
  16. const emits = defineEmits(['text-select', 'touch-start','touch-end'])
  17. // 按下
  18. function handleTouchStart() {
  19. btnStatus.value = true // 按下变红色
  20. emits('touch-start')
  21. }
  22. // 松开
  23. function handleTouchEnd() {
  24. btnStatus.value = false // 松开恢复蓝色
  25. emits('text-select')
  26. }
  27. </script>
  28. <style lang="scss" scoped>
  29. .active {
  30. color: red;
  31. }
  32. </style>