HeadersRenderer.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div>
  3. <div
  4. class="
  5. bg-primary
  6. border-b border-dividerLight
  7. flex flex-1
  8. top-lowerSecondaryStickyFold
  9. pl-4
  10. z-10
  11. sticky
  12. items-center
  13. justify-between
  14. "
  15. >
  16. <label class="font-semibold text-secondaryLight">
  17. {{ $t("request.header_list") }}
  18. </label>
  19. <div class="flex">
  20. <ButtonSecondary
  21. v-if="headers"
  22. ref="copyHeaders"
  23. v-tippy="{ theme: 'tooltip' }"
  24. :title="$t('action.copy')"
  25. :svg="copyIcon"
  26. @click.native="copyHeaders"
  27. />
  28. </div>
  29. </div>
  30. <div
  31. v-for="(header, index) in headers"
  32. :key="`header-${index}`"
  33. class="
  34. divide-x divide-dividerLight
  35. border-b border-dividerLight
  36. flex
  37. group
  38. "
  39. >
  40. <span
  41. class="
  42. flex flex-1
  43. min-w-0
  44. py-2
  45. px-4
  46. transition
  47. group-hover:text-secondaryDark
  48. "
  49. >
  50. <span class="rounded select-all truncate">
  51. {{ header.key }}
  52. </span>
  53. </span>
  54. <span
  55. class="
  56. flex flex-1
  57. min-w-0
  58. py-2
  59. px-4
  60. transition
  61. group-hover:text-secondaryDark
  62. "
  63. >
  64. <span class="rounded select-all truncate">
  65. {{ header.value }}
  66. </span>
  67. </span>
  68. </div>
  69. </div>
  70. </template>
  71. <script>
  72. import { defineComponent } from "@nuxtjs/composition-api"
  73. import { copyToClipboard } from "~/helpers/utils/clipboard"
  74. export default defineComponent({
  75. props: {
  76. headers: { type: Array, default: () => [] },
  77. },
  78. data() {
  79. return {
  80. copyIcon: "copy",
  81. }
  82. },
  83. methods: {
  84. copyHeaders() {
  85. copyToClipboard(JSON.stringify(this.headers))
  86. this.copyIcon = "check"
  87. this.$toast.success(this.$t("state.copied_to_clipboard"), {
  88. icon: "content_paste",
  89. })
  90. setTimeout(() => (this.copyIcon = "copy"), 1000)
  91. },
  92. },
  93. })
  94. </script>