btnTxt.vue 643 B

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