vue3项目利用iframe展示其他页面

本文介绍了HTML中的iframe元素,用于在页面中嵌入其他HTML内容。讨论了iframe的关键属性,如src、name、scrolling和frameborder。接着展示了一个Vue.js组件的例子,该组件使用iframe并处理加载状态、高度自适应及窗口resize事件。

一、什么是iframe?

iframe是html内联框架元素,它能够将另一个 HTML 页面嵌入到当前页面中。

主要属性如下:

src被嵌套的页面的 URL 地址
name

框架名称

scrolling否要在框架内显示滚动条。值; auto(仅当框架的内容超出框架的范围时显示滚动条)、yes、no
widthiframe的宽度
heightiframe的高度
frameborder值为1(默认值)时,显示此框架的边框。值为0时移除边框。

 二、组件例子

下面以组件的的形式举例:

<template>
  <div v-loading="loading" :style="{height: realHeight}">
    <iframe 
      :src="url" 
      scrolling="auto"
      frameborder="no" 
      style="width: 100%; height: 100%" 
     />
  </div>
</template>

<script setup>
const props = defineProps({
  src: {
    type: String,
    required: true
  }
})

const realHeight = ref(document.documentElement.clientHeight - 94.5 + "px;")
const loading = ref(true)
const url = computed(() => props.src)

onMounted(() => {
  setTimeout(() => { loading.value = false; }, 100);
  window.onresize = function (){
    realHeight.value = document.documentElement.clientHeight - 94.5 + "px;";
  };
})
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱吃彩虹吐司的安琪拉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值