index.vue 722 B

12345678910111213141516171819202122232425262728293031
  1. <template>
  2. <pre :class="'hx-scroll ' + lineNumbers"><code :class="'language-'+ type" v-html="Prism.highlight(code, Prism.languages[type], type)"></code></pre>
  3. </template>
  4. <script setup lang="ts">
  5. import Prism from 'prismjs'
  6. const props = defineProps({
  7. code: {
  8. type: String,
  9. default: ''
  10. },
  11. type: {
  12. type: String,
  13. default: 'xml'
  14. },
  15. isShowLineNumbers: {
  16. type: Boolean,
  17. default: false
  18. }
  19. })
  20. const lineNumbers = computed(() => {
  21. return props.isShowLineNumbers ? 'line-numbers' : ''
  22. })
  23. onMounted(() => {
  24. setTimeout(
  25. () => Prism.highlightAll() // 异步请求的数据,可在获取数据后调用此方法
  26. )
  27. })
  28. </script>
  29. <style lang="scss" scoped>
  30. @import './index.scss';
  31. </style>