GitCode.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <details class="custom-block details custom-code">
  3. <summary>查看代码:{{ fileUrl }}</summary>
  4. <pre class="line-numbers">
  5. <code class="language-typescript" v-html="code"></code>
  6. </pre>
  7. </details>
  8. </template>
  9. <script>
  10. import axios from "axios"
  11. export default {
  12. name: "GitCode",
  13. props:{
  14. project: {
  15. type: String,
  16. default: '/web/persagy-web'
  17. },
  18. raw: {
  19. type: String,
  20. default: '/raw/master'
  21. },
  22. fileUrl: {
  23. type: String,
  24. default: '/persagy-web-big/src/items/SIconTextItem.ts'
  25. },
  26. type: {
  27. type: String,
  28. default: 'typescript'
  29. }
  30. },
  31. data(){
  32. return{
  33. baseUrl: '/git',
  34. code:''
  35. }
  36. },
  37. created() {
  38. this.init()
  39. },
  40. computed:{
  41. requestUrl(){
  42. return this.baseUrl + this.project + this.raw + this.fileUrl;
  43. }
  44. },
  45. methods: {
  46. init(){
  47. axios({
  48. method: "get",
  49. url: this.requestUrl
  50. }).then(res => {
  51. this.code = res.data;
  52. this.$nextTick(()=>{
  53. document.querySelectorAll("pre code").forEach(block => {
  54. Prism.highlightElement(block)
  55. });
  56. });
  57. })
  58. }
  59. }
  60. }
  61. </script>
  62. <style scoped>
  63. </style>