Question.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div class="question">
  3. <div class="title">{{ title }}
  4. <button @click="onClick" :class="open ? 'active': ''">
  5. <svg v-if="open" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
  6. <path d="M5 11V13H19V11H5Z"></path>
  7. </svg>
  8. <svg v-else xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
  9. <path d="M11 11V5H13V11H19V13H13V19H11V13H5V11H11Z"></path>
  10. </svg>
  11. </button>
  12. </div>
  13. <transition name="fade">
  14. <div v-if="open" class="content">
  15. <slot/>
  16. </div>
  17. </transition>
  18. </div>
  19. </template>
  20. <script lang="ts" setup>
  21. import {ref} from 'vue';
  22. defineProps(['title'])
  23. const open = ref(false);
  24. const onClick = () => {
  25. open.value = !open.value
  26. }
  27. </script>
  28. <style scoped>
  29. .fade-enter-active, .fade-leave-active {
  30. transition: all .2s;
  31. }
  32. .fade-enter-from, .fade-leave-to {
  33. opacity: 0;
  34. transform: translateY(-3%);
  35. }
  36. .question {
  37. background: #f8f9fa;
  38. padding: 20px;
  39. border-radius: 5px;
  40. }
  41. .title {
  42. display: flex;
  43. justify-content: space-between;
  44. align-items: center;
  45. color: #000000;
  46. font-weight: bold;
  47. font-size: 16px;
  48. }
  49. button {
  50. background: #eee;
  51. display: flex;
  52. justify-content: center;
  53. align-content: center;
  54. width: 26px;
  55. height: 26px;
  56. border-radius: 6px;
  57. transition: all .3s;
  58. }
  59. .active {
  60. background: #000;
  61. }
  62. .active svg {
  63. fill: #fff;
  64. }
  65. svg {
  66. height: 26px;
  67. width: 26px;
  68. fill: #999;
  69. }
  70. .content {
  71. color: #999;
  72. margin: 10px 30px 0 0;
  73. }
  74. </style>