Blame view

src/components/preview.vue 1.25 KB
627f3fff   LH_PC   fix:前端知识点组件代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  <template>
      <div class="preview">
          <iframe v-if="type == 'html'" ref="iframe" :src="$props.src" style="width: 100%; height: 500px;" />
          <el-image v-if="type == 'image'" ref="iframe" :src="$props.src" style="width: 100%; height: 500px;" />
      </div>
  </template>
  <script>
  export default {
      name: "PreView",
      props: {
          src: "",
      },
      watch: {
          $props: {
              handler: function (val) {
                  console.log('change', val)
              },
              deep: false,
          }
      },
      data() {
          return {
              type: ""
          }
      },
      watch: {
          '$props.src'() {
              this._isCheckType();
          }
      },
      methods: {
          _isImagePath(path) {
              return /\.(jpg|jpeg|png|gif|bmp|svg|webp)$/i.test(path);
          },
          _isCheckType() {
              if (this._isImagePath(this.$props.src)) {
                  this.type = 'image'
              } else {
                  this.type = 'html'
              }
          }
      },
      created() {
          this._isCheckType();
      }
  }
  </script>
  <style scoped lang="scss">
  .preview {
  
      iframe,
      .el-image__inner {
          height: calc(100%-10px) !important;
          width: calc(100%-10px) !important;
          z-index: -1;
      }
  }
  </style>