码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • element-ui vue2 iframe 嵌入外链新解


    效果如图

    实现原理

    • 在路由中通过  props 传值

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

    1. <template>
    2. <div class="iframe-container">
    3. <iframe :src="src" scrolling="auto" frameborder="0" class="frame" :onload="onloaded()">
    4. iframe>
    5. div>
    6. template>
    7. <script>
    8. export default {
    9. props: ['url'] ,
    10. data() {
    11. return {
    12. src: this.$props.url,
    13. loading: null
    14. };
    15. },
    16. methods: {
    17. // 获取路径
    18. resetSrc: function(url) {
    19. this.src = url
    20. this.load()
    21. },
    22. load: function() {
    23. this.loading = this.$loading({
    24. lock: true,
    25. text: "loading...",
    26. spinner: "el-icon-loading",
    27. background: "rgba(0, 0, 0, 0.5)",
    28. // fullscreen: false,
    29. target: document.querySelector("#main-container ")
    30. })
    31. },
    32. onloaded: function() {
    33. if(this.loading) {
    34. this.loading.close()
    35. }
    36. }
    37. },
    38. mounted() {
    39. this.resetSrc(this.$props.url);
    40. },
    41. watch: {
    42. $route: {
    43. handler: function(val, oldVal) {
    44. // 如果是跳转到嵌套页面,切换iframe的url
    45. this.resetSrc(this.$props.url);
    46. }
    47. }
    48. }
    49. };
    50. script>
    51. <style lang="scss">
    52. .iframe-container {
    53. position: absolute;
    54. top: 0px;
    55. left: 0px;
    56. right: 0px;;
    57. bottom: 0px;
    58. .frame {
    59. width: 100%;
    60. height: 100%;
    61. }
    62. }
    63. style>

    参考

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

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

  • 相关阅读:
    彻底理解并解决服务器出现大量TIME_WAIT - 第四篇
    使用Python和BeautifulSoup提取网页数据的实用技巧
    常见的内网穿透工具有 ngrok/ localtunnel/ frp
    项目测试排期的正确方法是什么?
    使用Docker部署Jenkins
    OWASP Top 10 2022 介紹
    python的网络请求库urllib、urllib2、urllib3、request的联系
    Altassian | Bitbucket Python API使用及相关任务自动化的实现
    C#进阶-ASP.NET常用控件总结
    鸢尾花数据种类预测、分析与处理、scikit-learn数据集使用、seaborn作图及数据集的划分
  • 原文地址:https://blog.csdn.net/qq_34068440/article/details/134084834
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号