vue项目中嵌套外部网页

主要有两种方法:

一、通过接口请求,然后v-html渲染,这种方法试验之后发现不行,v-html不会渲染内部页面

二、iframe的方式(解决引入成功之后获取不到引入的标签问题及跨域问题

需要嵌套的网页地址为:http://10.108.230.74:8080/smartbi/vision/openresource.jsp

config.js文件中设置代理:

dev: {
    env: require('./dev.env'),
    host: '0.0.0.0',
    port: '8080',
    autoOpenBrowser: true,
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',
    proxyTable: {
      '/jsp': {
        target: 'http://10.108.230.74:8080', // 接口地址
        changeOrigin: true, // 是否跨域
        pathRewrite: { // 转发
            '^/jsp': ''
        },
        secure: false,
        headers: {
          Referer: 'https://10.108.230.74:8080'
        }
      },
    },

备注:代理里面https的url才需要加headers的参数

在页面引入:

<iframe src="jsp/smartbi/vision/openresource.jsp" width="100%" height="800" frameborder="0" scrolling="auto" id="iframename" name="iframename"></iframe>

获取iframe页面里某个标签

var i = document.getElementById('iframename');
i.onload = function(){
console.log(i.contentWindow.document)
console.log(i.contentWindow.document.getElementsByClassName("login-user-input"))
}

原文地址:https://www.cnblogs.com/www3j/p/13093393.html