Child.vue 880 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <template>
  2. <div>
  3. <button :class="btnClass">{{ text }}</button>
  4. </div>
  5. </template>
  6. <script lang="ts" setup>
  7. import { ref, reactive, computed } from "vue";
  8. const props = defineProps({
  9. size: {
  10. type: String as () => "sm" | "md" | "bi",
  11. default: "md",
  12. },
  13. color: {
  14. type: String as () => "small" | "middle" | "big",
  15. default: "middle",
  16. },
  17. text: String,
  18. });
  19. const btnClass = computed(() => {
  20. const sizeMap = {
  21. sm: "px-3 py-1 text-sm",
  22. md: "px-5 py-2 text-xs",
  23. bi: "px-7 py-3 text-lg",
  24. };
  25. const colorMap = {
  26. small: "bg-red-300 hover:bg-red-600",
  27. middle: "bg-blue-300 hover:bg-blue-600",
  28. big: "bg-green-300 hover:bg-green-600",
  29. };
  30. return [
  31. "rounded-lg text-white transition-all duration-300 active:scale-95",
  32. sizeMap[props.size],
  33. colorMap[props.color],
  34. ];
  35. });
  36. </script>
  37. <style lang="scss" scoped>
  38. </style>