ParameterTable.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <template>
  2. <div class="para-tab-wrap">
  3. <div v-for="(item, index) in items" :key="index" class="para-tab-row">
  4. <div class="para-tab-name" :style="{ width: labelWidth }" v-html="safeHtml(item.name)"></div>
  5. <div class="para-tab-content" v-html="safeHtml(item.content)"></div>
  6. </div>
  7. </div>
  8. </template>
  9. <script setup lang="ts">
  10. defineProps({
  11. labelWidth: {
  12. type: String,
  13. default: '150px' // 默认 150px
  14. },
  15. items: {
  16. type: Array,
  17. required: true,
  18. default: () => []
  19. }
  20. });
  21. // 防止 XSS
  22. function safeHtml(name: string) {
  23. return name
  24. .replace(/</g, '&lt;')
  25. .replace(/>/g, '&gt;')
  26. .replace(/&lt;br&gt;/g, '<br>');
  27. }
  28. </script>
  29. <style scoped>
  30. .para-tab-wrap {
  31. display: flex;
  32. flex-direction: column;
  33. gap: 20px;
  34. width: 100%;
  35. padding-top: 30px;
  36. padding-bottom: 30px;
  37. }
  38. .para-tab-row {
  39. display: flex;
  40. gap: 20px;
  41. }
  42. .para-tab-name {
  43. white-space: normal; /* 默认可以换行 */
  44. font-weight: bold;
  45. color: #333;
  46. }
  47. .para-tab-content {
  48. white-space: normal; /* 默认可以换行 */
  49. flex: 1;
  50. }
  51. </style>