当前位置: 首页 > news >正文

element-ui vue2 iframe 嵌入外链新解

效果如图

实现原理

  • 在路由中通过  props 传值

  {path: '/iframe',component: Layout,meta: { title: '小助手', icon: 'example' },children: [{path: 'chatglm',name: 'chatglm',props: {  name: 'chatglm',url: 'https://chatglm.cn' },component: () => import('@/views/iframe/common'),meta: { title: 'ai-智普清言', icon: 'table' }},
]
  • 组件中获取数据  this.$props.url

<template><div class="iframe-container"><iframe :src="src" scrolling="auto" frameborder="0" class="frame" :onload="onloaded()"></iframe></div></template><script>export default {props: ['url']  ,data() {return {src: this.$props.url,loading: null};},methods: {// 获取路径resetSrc: function(url) {this.src = urlthis.load()},load: function() {this.loading = this.$loading({  lock: true,text: "loading...",spinner: "el-icon-loading",background: "rgba(0, 0, 0, 0.5)",// fullscreen: false,target: document.querySelector("#main-container ")})},onloaded: function() {if(this.loading) {this.loading.close()}}},mounted() {this.resetSrc(this.$props.url);},watch: {$route: {handler: function(val, oldVal) {// 如果是跳转到嵌套页面,切换iframe的urlthis.resetSrc(this.$props.url);}}}};</script><style lang="scss">.iframe-container {position: absolute;top: 0px;left: 0px;right: 0px;;bottom: 0px;.frame {width: 100%;height: 100%;}}</style>

参考

src/views/IFrame/IFrame.vue · 朝雨忆轻尘(Louis)/kitty-ui - Gitee.com

Vue 路由组件传参的 8 种方式 - 掘金

http://www.lryc.cn/news/208687.html

相关文章:

  • win10 + VS2017 编译libjpeg(jpeg-9b)
  • 如何实现公网远程桌面访问Ubuntu?VNC+cpolar内网穿透!
  • SpringMvc接收参数
  • 计算机网络文章荟萃
  • C# Socket通信从入门到精通(4)——多个异步TCP客户端C#代码实现
  • GitHub为自己的仓库(Repository)设置默认代码缩进(tabsize)
  • Tomcat的动静分离
  • Chimera:混合的 RLWE-FHE 方案
  • MySQL 连接出现 Authentication plugin ‘caching_sha2_password的处理方法(使用第二种)
  • 设置Ubuntu 20.04的静态IP地址(wifi模式下)
  • Qt界面实现中英文切换
  • Python 编写确定个位、十位以上方法及各数位的和程序
  • AI 引擎系列 1 - 从 AI 引擎工具开始(2022.1 更新)
  • Android Kotlin 协程初探 | 京东物流技术团队
  • MySQL-DQL【数据查询语言】(图码结合)
  • HTTP 响应状态码介绍
  • vtk 绘制等高线
  • N-129基于springboot,vue学生宿舍管理系统
  • 力扣每日一题70:爬楼梯
  • 分布式合集
  • MySQL比较两个表数据的差异
  • hive使用中的参数优化与问题排查
  • Leetcode—66.加一【简单】
  • Babylonjs学习笔记(六)——贴图的使用
  • 架构风格区别-架构案例(五十九)
  • p5.js画布操作实战:创建,绑定指定元素,动态调整大小,隐藏滚动条,删除画布
  • vue手动拖入和导入excel模版
  • Linux下导出dump文件(Oracle和PG数据)
  • TSINGSEE青犀睡岗离岗检测算法——确保加油站安全运营
  • gd32部分映射1/2,完全映射,备用功能选择等