SimpleRemoveRichHtml.vue 608 B

123456789101112131415161718192021222324
  1. <template>
  2. <span>{{ removeHtmlTags(content) }}</span>
  3. </template>
  4. <script setup lang="ts">
  5. const props = defineProps({
  6. content: {
  7. type: String,
  8. default: '',
  9. },
  10. })
  11. function removeHtmlTags(str: string) {
  12. str = str.replace(/<[^>]*>/g, '');
  13. str = str.replace(/&nbsp;/gi, ' '); // 替换为普通空格
  14. str = str.replace(/&amp;/gi, '&'); // 替换为 &
  15. str = str.replace(/&lt;/gi, '<'); // 替换为 <
  16. str = str.replace(/&gt;/gi, '>'); // 替换为 >
  17. str = str.replace(/&quot;/gi, '"'); // 替换为 "
  18. str = str.replace(/&#39;/gi, "'"); // 替换为 '
  19. return str;
  20. }
  21. </script>