失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > vue 给iframe设置src_vue组件中使用iframe元素

vue 给iframe设置src_vue组件中使用iframe元素

时间:2020-11-12 01:35:07

相关推荐

vue 给iframe设置src_vue组件中使用iframe元素

需要在本页面中展示vue组件中的超链接,地址栏不改变的方法:

GoBack

{{item.name}}

export default {

name: 'hello',

data () {

return {

iframeState:false,

goBackState:false,

webAddress: [

{

name:'segmentFault',

link:'/a/1190000004502619'

},

{

name:'博客',

link:'/'

},

{

name:'特效',

link:'/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;

}

}

}

需要使同层元素不被覆盖,可以加

不过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设置src_vue组件中使用iframe元素》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。