vue使用iframe嵌入网页的示例代码
网络编程 2021-07-04 17:33www.168986.cn编程入门
本篇文章主要介绍了vue使用iframe嵌入网页的示例代码,长沙网络推广觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随长沙网络推广过来看看吧
1、列表页面
this.$router.push({ name: 'userTemplate', params: { reportUrl: reportUrl, reportType: reportType }})
点击查看后触发事件,带入参数跳转到userTemplate页面;reportType有两种类型,0表示reportUrl是绝对网址,1表示reportUrl是本地html文件。
2、userTemplate页面
<template> <div> <iframe v-if="reportType==0" name = "child" id = "child" v-bind:src="reportUrl" width="auto" height="300" frameborder="0" scrolling="no" style="position:absolute;:80px;left: 30px;" ></iframe> <div v-if="reportType==1" v-html="htmlContent" width="auto" height="300" scrolling="no" style="position:absolute;:80px;left: 30px;"></div> </div> </template> <script> 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 } }) } } } </script> <style rel="stylesheet/scss" lang="scss" scoped> </style>
后端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.getSuessInstance(result); }catch(Exception e){ e.printStackTrace(); return HttpResult.getFailedInstance("读取异常"); } }
到此这篇关于vue使用iframe嵌入网页的示例代码的文章就介绍到这了,更多相关vue使用iframe嵌入网页内容请搜索狼蚁SEO以前的文章或继续浏览狼蚁网站SEO优化的相关文章希望大家以后多多支持狼蚁SEO!
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指