vue iframe加载loading效果

<template>
  <div style="height:100%;overflow: auto;" v-loading="loading">
    <iframe ref="iframe" :src="https://juejin.cn/post/src" width="100%" height="100%" frameborder="0"></iframe>
  </div>
</template>

<script>
export default {
  data() {
    return {
      src: 'https://www.baidu.com',
      loading: true,
    };
  },
  created() {

  },
  mounted() {
    const { iframe } = this.$refs;
    // IE和非IE浏览器,监听iframe加载事件不一样,需要兼容
    const that = this;
    if (iframe.attachEvent) {
      // IE
      iframe.attachEvent('onload', () => {
        that.stateChange();
      });
    } else {
      // 非IE
      iframe.onload = function () {
        that.stateChange();
      };
    }
  },
  methods: {
    stateChange() {
      this.loading = false;
    },
  },
};
</script>
<style scoped></style>
复制代码
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享