vue使用iframe嵌套html页面,vue使用iframe嵌入网页的示例代码

编程知识 更新时间:2023-04-04 23:50:43

1、列表页面:

this.$router.push({ name: 'userTemplate', params: { reportUrl: reportUrl, reportType: reportType }})

点击查看后触发事件,带入参数跳转到userTemplate页面;reportType有两种类型,0表示reportUrl是绝对网址,1表示reportUrl是本地html文件。

2、userTemplate页面:

width="auto" height="300"

frameborder="0" scrolling="no" style="position:absolute;top:80px;left: 30px;"

>

width="auto" height="300" scrolling="no" style="position:absolute;top:80px;left: 30px;">

import {

getFile

} from '@/api/report'

export default {

mounted() {

/**

* iframe-宽高自适应显示

*/

function changeMobsfIframe() {

const mobsf = document.getElementById('child')

const deviceWidth = document.body.clientWidth

const deviceHeight = document.body.clientHeight

mobsf.style.width = (Number(deviceWidth) - 30) + 'px' // 数字是页面布局宽度差值

mobsf.style.height = (Number(deviceHeight) - 80) + 'px' // 数字是页面布局高度差

}

changeMobsfIframe()

window.onresize = function() {

changeMobsfIframe()

}

},

data() {

return {

htmlContent: '',

reportUrl: '',

reportType: ''

}

},

created() {

// this.fileName = '../static/file/' + this.$route.params.report_url

this.reportUrl = this.$route.params.reportUrl

this.reportType = this.$route.params.reportType

if (this.reportType == 1) {

getFile(this.reportUrl).then(res => {

if (res.code === 200) {

this.htmlContent = res.data

}

})

}

}

}

后端getFile:

//读取文件

@RequestMapping("/getFile")

@ResponseBody

public HttpResult getFile(String reportUrl){

StringBuilder result = new StringBuilder();

try{

FileSystemResource resource = new FileSystemResource("D:"+File.separator+"test"+File.separator+reportUrl);

File file = resource.getFile();

BufferedReader br = new BufferedReader(new FileReader(file));

String s = null;

while((s = br.readLine())!=null){

result.append(System.lineSeparator()+s);

}

br.close();

return HttpResult.getSuccessInstance(result);

}catch(Exception e){

e.printStackTrace();

return HttpResult.getFailedInstance("读取异常");

}

}

到此这篇关于vue使用iframe嵌入网页的示例代码的文章就介绍到这了,更多相关vue使用iframe嵌入网页内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

更多推荐

vue使用iframe嵌套html页面,vue使用iframe嵌入网页的示例代码

本文发布于:2023-04-04 23:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/3686e3a68b4e5360f0f5b1e85ab1e644.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   示例   页面   代码   网页

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 43774文章数
  • 14阅读数
  • 0评论数