>  기사  >  웹 프론트엔드  >  Vue 구성 요소에서 iframe 요소를 사용하는 방법의 예

Vue 구성 요소에서 iframe 요소를 사용하는 방법의 예

小云云
小云云원래의
2018-05-15 11:34:296296검색

이 글은 주로 Vue 컴포넌트에서 iframe 요소를 사용하기 위한 샘플 코드를 소개합니다. 편집자는 이것이 꽤 좋다고 생각합니다. 이제 여러분과 공유하고 참고할 수 있기를 바랍니다.

이 페이지의 vue 구성 요소에 하이퍼링크를 표시해야 하며 주소 표시줄은 변경되지 않습니다.

<template>
 <p class="accept-container">
   <p class="go-back" v-show="goBackState" @click="goBack">GoBack</p>
<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>
 </p>
</template>
<script>
export default {
 name: &#39;hello&#39;,
 data () {
 return {
  iframeState:false,
  goBackState:false,
  webAddress: [
  {
   name:&#39;segmentFault&#39;,
   link:&#39;https://segmentfault.com/a/1190000004502619&#39;
  },
  {
   name:&#39;博客&#39;,
   link:&#39;http://vuex.vuejs.org/&#39;
  },
  {
   name:&#39;特效&#39;,
   link:&#39;http://www.yyyweb.com/377.html&#39;
  }
  ]
 }
 },
 mounted(){
 const oIframe = document.getElementById(&#39;show-iframe&#39;);
 const deviceWidth = document.documentElement.clientWidth;
 const deviceHeight = document.documentElement.clientHeight;
 oIframe.style.width = deviceWidth + &#39;px&#39;;
 oIframe.style.height = deviceHeight + &#39;px&#39;;
 },
 methods:{
 goBack(){
  this.goBackState = false;
  this.iframeState = false;
 },
 showIframe(){
  this.goBackState = true;
  this.iframeState = true;
 }
 }
}
</script>
<style scoped>
</style>

동일 레이어 요소가 가려지는 것을 방지해야 하며 추가할 수 있습니다.

코드 복사 코드는 다음과 같습니다:

52d8d7563cb9d658032bd12a52b72bce065276f04003e4622c4fe6b64f465b88

하지만 html5에는 대화 상자에 대한 새로운 대화 상자 요소가 있습니다.

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;

예:

<iframe 
id="google_ads_frame2"
 name="google_ads_frame2" 
 width="160" height="600" 
 frameborder="0" src="target.html"
  marginwidth="0" marginheight="0" 
  vspace="0" hspace="0" 
  allowtransparency="true" 
  scrolling="no" allowfullscreen="true">
  </iframe>

관련 권장 사항:

vue 구성 요소 3

vue 구성 요소를 npm

vue2.0 데이터 양방향 바인딩 및 형식 부트스트랩+vue 구성 요소

에 대한 자세한 설명

위 내용은 Vue 구성 요소에서 iframe 요소를 사용하는 방법의 예의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.