Markdown.vue 929 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <script lang="ts" setup>
  2. import { marked } from 'marked'
  3. import { ref } from 'vue'
  4. const props = defineProps({
  5. body: {
  6. type: Object,
  7. default: () => {}
  8. }
  9. })
  10. const text = ref('')
  11. const timer: any = ref()
  12. console.log(props.body.messageProps)
  13. const content = () => {
  14. const tempText = props.body.messageProps.text
  15. const len = tempText.length
  16. let num = 0
  17. let string = ''
  18. timer.value = setInterval(() => {
  19. if (num >= len) {
  20. clearInterval(timer.value)
  21. timer.value = null
  22. // this.saveHistory(this.preRecord)
  23. // resolve(true)
  24. return
  25. }
  26. // 持续保持滚动最底
  27. if (num % 10 === 0) {
  28. setTimeout(() => {
  29. // this.messageScroll()
  30. })
  31. }
  32. string = `${string}${tempText[num]}`
  33. text.value = marked(string) as string
  34. num++
  35. }, 50)
  36. }
  37. content()
  38. </script>
  39. <template>
  40. <div v-html="text"></div>
  41. </template>
  42. <style scoped lang="less"></style>