index.vue 1.38 KB
<template>
  <div class="adapter-home" id="adapter-frame" ref="adapter-frame"></div>
</template>

<script>
import { Postmate } from "glsx-common";
export default {
  name: "GLExternal",
  props: {
    url: {
      type: String,
      required: true,
    },
    subscribe: {
      type: Function,
      default: null,
    },
  },
  data() {
    return {
      container: null,
    };
  },
  mounted() {
    this.container = this.$refs["adapter-frame"];
    this.create();
  },

  methods: {
    create() {
      if (!this.url) throw new Error("url为空");
      this.container.innerHTML = "";
      var postmate = new Postmate({
        container: this.container,
        url: this.url,
        name: "adapter-frame",
        classListArray: ["gl-external-adapter-frame"],
      })
        .then((child) => {
          child.get("height").then((height) => {
            child.frame.setAttribute("scrolling", "no");
            child.frame.style.height = `${height}px`;
          });
          this.subscribe && this.subscribe(child);
        })
        .catch((err) => {
          console.log(err);
          throw new Error("连接失败: " + this.url);
        });
    },
  },
};
</script>
<style>
.gl-external-adapter-frame {
  width: 100%;
  min-height: calc(100vh - 90px);
  border: 0;
  overflow-y: hidden;
  box-sizing: border-box;
  /* position: absolute; */
  transition: all 0.48s ease;
}
</style>