本文介绍了vue组件中使用iframe元素的示例代码,分享给大家,具体如下:
创新互联建站主营武清网站建设的网络公司,主营网站建设方案,app软件开发,武清h5成都微信小程序搭建,武清网站营销推广欢迎武清等地区企业咨询
需要在本页面中展示vue组件中的超链接,地址栏不改变的方法:
<template> <div class="accept-container"> <div class="go-back" v-show="goBackState" @click="goBack">GoBack</div> <ul> <li v-for="item in webAddress"> <a :href="item.link" rel="external nofollow" target="showHere" @click="showIframe">{{item.name}}</a> </li> </ul> <iframe v-show="iframeState" id="show-iframe" frameborder=0 name="showHere" scrolling=auto src=""></iframe> </div> </template> <script> export default { name: 'hello', data () { return { iframeState:false, goBackState:false, webAddress: [ { name:'segmentFault', link:'https://segmentfault.com/a/1190000004502619' }, { name:'博客', link:'http://vuex.vuejs.org/' }, { name:'特效', link:'http://www.yyyweb.com/377.html' } ] } }, mounted(){ const oIframe = document.getElementById('show-iframe'); const deviceWidth = document.documentElement.clientWidth; const deviceHeight = document.documentElement.clientHeight; oIframe.style.width = deviceWidth + 'px'; oIframe.style.height = deviceHeight + 'px'; }, methods:{ goBack(){ this.goBackState = false; this.iframeState = false; }, showIframe(){ this.goBackState = true; this.iframeState = true; } } } </script> <style scoped> </style>
需要使同层元素不被覆盖,可以加
不过html5有新的dialog元素用于对话框。
iframe的一些方法:
获取iframe内容:
var iframe = document.getElementById("iframe1"); var iwindow = iframe.contentWindow; var idoc = iwindow.document; console.log("window",iwindow);//获取iframe的window对象 console.log("document",idoc); //获取iframe的document console.log("html",idoc.documentElement);//获取iframe的html console.log("head",idoc.head); //获取head console.log("body",idoc.body); //获取body
自适应 iframe:
即1去掉滚动条,2设置宽高
var iwindow = iframe.contentWindow; var idoc = iwindow.document; iframe.height = idoc.body.offsetHeight;
例子:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持创新互联。
网页标题:vue组件中使用iframe元素的示例代码
链接分享:https://www.cdcxhl.com/article26/poopcg.html
成都网站建设公司_创新互联,为您提供电子商务、营销型网站建设、定制开发、手机网站建设、企业建站、面包屑导航
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联