123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <template>
- <details class="custom-block details custom-code">
- <summary>查看源代码:{{ fileUrl }}</summary>
- <pre class="line-numbers">
- <code class="language-typescript" v-html="code"></code>
- </pre>
- </details>
- </template>
- <script>
- import axios from "axios"
- export default {
- name: "GitCode",
- props:{
- project: {
- type: String,
- default: '/web/persagy-web'
- },
- raw: {
- type: String,
- default: '/raw/master'
- },
- fileUrl: {
- type: String,
- default: '/persagy-web-big/src/items/SIconTextItem.ts'
- },
- type: {
- type: String,
- default: 'typescript'
- }
- },
- data(){
- return{
- baseUrl: '/git',
- username: 'lbsl',
- password: '20200829',
- code:''
- }
- },
- created() {
- this.init()
- },
- computed:{
- requestUrl(){
- return this.baseUrl + this.project + this.raw + this.fileUrl;
- }
- },
- methods: {
- init(){
- axios({
- method: "get",
- url: this.requestUrl
- }).then(res => {
- this.code = res.data;
- this.$nextTick(()=>{
- // 此处选择器 只选择当前组件的pre code,否则影响组件外 代码区域 格式
- document.querySelectorAll(".custom-code pre code").forEach(block => {
- Prism.highlightElement(block)
- });
- });
- })
- }
- }
- }
- </script>
- <style scoped>
- </style>
|