跨域问题
'/webroot/decision': {
  target: 'http://ip:端口',
  changeOrigin: true,
  pathRewrite: {
    '^/webroot/decision': '/webroot/decision'
  }
}
.vue
<template>
  <div class="sheetWrap">
    <div style="position: relative; width: 100%; height: 100%">
      <iframe
        ref="iframe"
        src=""
        style="
          margin: 0px;
          padding: 0px;
          position: absolute;
          width: 100%;
          height: 100%;
          left: 0px;
          top: 0px;
        "
        frameborder="0"
      ></iframe>
    </div>
  </div>
</template>
<script>
import axios from 'axios'
import { store } from '@/utils/sunmei-data'

export default {
  name: '',
  data() {
    return {
      // iframeSrc: 'http://ip:端口/webroot/decision/view/report?viewlet=cpt文件名.cpt&op=write'
    }
  },
  mounted() {
    // 携带token,此配置需要在数据决策系统中配置用户(一用户一账号)
    // this.getToken()
    // 无需登录(数据决策系统中关闭模板认证)
    this.getIframe()
  },
  methods: {
    getToken() {
      axios
        .get(
          '/webroot/decision/login/cross/domain?fine_username=admin&fine_password=123456&validity=-1'
        )
        .then((res) => {
          const strD = res.data.replace('callback(', '')
          const str = strD.substring(0, strD.length - 1)
          const strF = JSON.parse(str)
          this.getIframe([['Authorization', 'Bearer ' + strF.accessToken]])
        })
      return ''
    },
    getIframe(headers = []) {
      const xhr = new XMLHttpRequest()
      xhr.open(
        'GET',
        `/webroot/decision/view/report?viewlet=${
          cpt文件名
        }.cpt&op=write`
      )
      xhr.responseType = 'text'
      headers.forEach((header) => {
        xhr.setRequestHeader(header[0], header[1])
      })
      xhr.onreadystatechange = () => {
        if (xhr.readyState === xhr.DONE) {
          if (xhr.status === 200) {
            let iframe = this.$refs.iframe
            iframe =
              iframe.contentWindow || iframe.contentDocument.document || iframe.contentDocument
            iframe.document.open()
            iframe.document.write(xhr.response)
            iframe.document.close()
          }
        }
      }
      xhr.send()
    }
  }
}
</script>

<style lang="scss" scoped>
.sheetWrap {
  // 指定样式宽度
  width: 100%;
  height: 100%;
  overflow: auto;
}
</style>

GitHub 加速计划 / vu / vue
207.52 K
33.66 K
下载
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:1 个月前 )
73486cb5 * chore: fix link broken Signed-off-by: snoppy <michaleli@foxmail.com> * Update packages/template-compiler/README.md [skip ci] --------- Signed-off-by: snoppy <michaleli@foxmail.com> Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 3 个月前
e428d891 Updated Browser Compatibility reference. The previous currently returns HTTP 404. 3 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐