md-preview.vue 1.3 KB
Newer Older
璃白.'s avatar
璃白. 已提交
1
<template>
璃白.'s avatar
fix  
璃白. 已提交
2
  <div :class="['md_preview', { fullScreen }]">
璃白.'s avatar
璃白. 已提交
3 4 5 6 7 8 9
    <div
      v-html="html"
      :style="{
        height: height > 0 ? height + 'px' : 'auto',
        'min-height': htmlMinHeight + 'px'
      }"
    ></div>
璃白.'s avatar
璃白. 已提交
10 11 12 13 14
  </div>
</template>
<script>
export default {
  data() {
璃白.'s avatar
fix  
璃白. 已提交
15
    return {};
璃白.'s avatar
璃白. 已提交
16
  },
璃白.'s avatar
璃白. 已提交
17
  props: {
璃白.'s avatar
璃白. 已提交
18 19 20 21
    id: {
      type: String,
      default: ""
    },
璃白.'s avatar
璃白. 已提交
22
    text: {
璃白.'s avatar
璃白. 已提交
23
      type: [String, Number],
璃白.'s avatar
璃白. 已提交
24 25
      default: ""
    },
璃白.'s avatar
fix  
璃白. 已提交
26 27 28
    htmlMinHeight: {
      default: ""
    },
璃白.'s avatar
璃白. 已提交
29 30 31 32
    height: {
      type: Number,
      default: 0
    },
璃白.'s avatar
璃白. 已提交
33
    html: {
璃白.'s avatar
璃白. 已提交
34
      type: [String, Promise],
璃白.'s avatar
璃白. 已提交
35
      default: ""
璃白.'s avatar
璃白. 已提交
36 37 38 39
    },
    fullScreen: {
      type: Boolean,
      default: false
璃白.'s avatar
璃白. 已提交
40
    }
璃白.'s avatar
璃白. 已提交
41
  },
璃白.'s avatar
fix  
璃白. 已提交
42 43 44 45 46 47
  mounted() {
    this.addClass();
  },
  updated() {
    this.addClass();
  },
璃白.'s avatar
璃白. 已提交
48
  methods: {
璃白.'s avatar
fix  
璃白. 已提交
49 50
    addClass() {
      setTimeout(() => {
璃白.'s avatar
fix  
璃白. 已提交
51 52 53
        const previewDomList = document.querySelectorAll(".md_preview code");
        if (!previewDomList.length) return;
        previewDomList.forEach(item => {
54
          item.className += " md_hljs";
璃白.'s avatar
fix  
璃白. 已提交
55
        });
璃白.'s avatar
fix  
璃白. 已提交
56
      }, 0);
璃白.'s avatar
璃白. 已提交
57 58 59 60 61
    }
  }
};
</script>
<style lang="less" scoped>
璃白.'s avatar
fix  
璃白. 已提交
62
.md_preview {
璃白.'s avatar
璃白. 已提交
63 64
  // min-height: 148px;
  padding: 14px 0;
璃白.'s avatar
璃白. 已提交
65 66 67
  box-sizing: border-box;
  color: var(--md-editor-text-color);
  word-break: break-all;
璃白.'s avatar
璃白. 已提交
68 69 70 71
  overflow-y: auto;
  & > div {
    overflow-y: auto;
  }
璃白.'s avatar
璃白. 已提交
72 73 74 75
  &.fullScreen {
    max-height: calc(100% - 42px);
    overflow-y: auto;
  }
璃白.'s avatar
璃白. 已提交
76 77
}
</style>