基于vue-element-admin框架改造——支持第三方iframe网站


声明:本文转载自https://my.oschina.net/sunshineS/blog/1615716,转载目的在于传递更多信息,仅供学习交流之用。如有侵权行为,请联系我,我会及时删除。

先来看个效果图

码云地址:https://gitee.com/smallweigit/vue-element-admin.git

例:http://localhost:9527/#/iframe/urlPath?src=https://www.baidu.com (访问百度)

格式:http://localhost:9527/#/iframe/urlPath?src=第三方的网站

并且支持判断iframe是否加载完成的等待框以及浏览器窗口变化做出的响应

改造代码

./src/views/iframe/index.vue(第三方iframe组件)

<template> 	<iframe v-if="$route.query.src" :src='$route.query.src' class="iframe" ref="iframe" v-loading.fullscreen.lock="fullscreenLoading"></iframe>     <iframe v-else :src="urlPath" class="iframe" ref="iframe" v-loading.fullscreen.lock="fullscreenLoading"></iframe>   </template>  <script> export default {   name: 'myiframe',   data() {     return {       fullscreenLoading: false,       urlPath: this.getUrlPath()     }   },   created() {     this.fullscreenLoading = true   },   mounted() {     this.iframeInit()     window.onresize = () => {       this.iframeInit()     }   },   props: ['routerPath'],   watch: {     routerPath: function(val) {       this.urlPath = this.getUrlPath()     }   },   components: {},   methods: {     iframeInit() {       const iframe = this.$refs.iframe       const clientHeight = document.documentElement.clientHeight - 90       iframe.style.height = `${clientHeight}px`       if (iframe.attachEvent) {         iframe.attachEvent('onload', () => {           this.fullscreenLoading = false         })       } else {         iframe.onload = () => {           this.fullscreenLoading = false         }       }     },     getUrlPath: function() {       let url = window.location.href       url = url.replace('/iframe', '')       return url     }   } } </script>  <style> .iframe {   width: 100%;   height: 100%;   border: 0;   overflow: hidden;   box-sizing: border-box; } </style>

./src/router/reouter/index.js(增加路由)

{     path: '/iframe',     component: Layout,     redirect: '/iframe', // you can set roles in root nav     children: [{       path: ':routerPath',       component: _import('iframe/index'),       name: 'iframe',       meta: {         title: 'iframe',         icon: 'people'       }     }]   },

./src/store/modules/tagsView.js(让vue-router路由可以获取完整的url路径)

将全部的view.path改成view.fullPath

if (state.visitedViews.some(v => v.path === view.fullPath)) return       state.visitedViews.push({         name: view.name,         path: view.fullPath,         title: view.meta.title || 'no-name'       })       if (!view.meta.noCache) {         state.cachedViews.push(view.name)       }

 

本文发表于2018年01月30日 22:32
(c)注:本文转载自https://my.oschina.net/sunshineS/blog/1615716,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如有侵权行为,请联系我们,我们会及时删除.

阅读 4932 讨论 0 喜欢 0

抢先体验

扫码体验
趣味小程序
文字表情生成器

闪念胶囊

你要过得好哇,这样我才能恨你啊,你要是过得不好,我都不知道该恨你还是拥抱你啊。

直抵黄龙府,与诸君痛饮尔。

那时陪伴我的人啊,你们如今在何方。

不出意外的话,我们再也不会见了,祝你前程似锦。

这世界真好,吃野东西也要留出这条命来看看

快捷链接
网站地图
提交友链
Copyright © 2016 - 2021 Cion.
All Rights Reserved.
京ICP备2021004668号-1