vue中iframe加載慢,給它加loading效果


js框架:vue

ui框架:element

因為iframe加載慢,所以在它加載完成前添加loading效果,loading用的是element家的加載效果 

<template>
  <div style="height:100%;overflow: auto;" v-loading="loading">
    <iframe ref="iframe" :src="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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM