<template>
  <div class="container">
    <div style="overflow:auto;" v-loading="loading">
      <iframe ref="iframe"  :src="newsUrl"  scrolling='auto' frameborder="0"></iframe>
    </div>
  </div>
</template>

<script>
  import {getToken} from '@/utils/auth'

  export default {
    name: "NewsList",
    data() {
      return {
        token: '',
        src: '',
        loading: true,
      }
    },
    methods: {
      stateChange() {
        this.loading = false;
      }
    },
    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();
        };
      }
    },
    computed: {
       newsUrl: function(){
         return this.src + "?token="+ this.token;
       }
    },
    created() {
      this.token = getToken();
      this.getClientConfigKey("cms.url").then((response) => {
        this.src = response.msg;
      });
    },
    beforeCreate () {
      document.querySelector('body').setAttribute('style', 'overflow:hidden;')
    },
    beforeDestroy () {
      document.querySelector('body').removeAttribute('style')
    },
  }
</script>
<style scoped>
</style>
