vue使用iframe引入页面

vue yekong 653℃

vue项目开发时可能会使用iframe引入页面,留个实例,方便后期用到的时候回查

<template>
  <div>
    <iframe class="iframe" id="template-iframe" ref="iframe" :src="src" @load="loaded"></iframe>
  </div>
</template>

<script>
export default {
  data () {
    return {
      iframeWin: {}
    }
  },
  computed: {
    src () {
      return 'https://www.wanjunshijie.com'
    }
  },
  methods: {
    loaded () {
      const cookie = document.cookie
      this.iframeWin.postMessage(cookie, this.src)
    }
  },
  mounted () {
    this.iframeWin = this.$refs.iframe.contentWindow
  }
}
</script>
<style lang="scss" scoped>
.iframe {
  position: fixed;
  width: 100%;
  height: 100%;
  border: none;
}
</style>

喜欢 (0)