Browse Source

志愿商城的iframe实现

feature
duanliangtao 11 months ago
parent
commit
28c30ebf7a
  1. 71
      src/views/modules/volunteer/mall/index.vue

71
src/views/modules/volunteer/mall/index.vue

@ -0,0 +1,71 @@
<template>
<div>
<!-- 隐藏 iframe等子页面加载完成并修改后再显示 -->
<iframe
id="childIframe"
ref="childIframe"
:src="iframeSrc"
width="100%"
height="1000px"
frameborder="0"
style="display: none;"
@load="onIframeLoad"
></iframe>
</div>
</template>
<script>
import http from "@/utils/request";
export default {
data() {
return {
//
iframeSrc: '', // iframeSrc
};
},
created() {
// ,ticket
http.get("/auth/sso/getTicket")
.then(({data: res}) => {
let ticket = res.data
console.log('ticket:', ticket)
this.iframeSrc = "../../../epmet-voluntary-mall-admin/pms/product?target=_blank&ticket=" + ticket
})
},
methods: {
// iframe
onIframeLoad() {
// iframe
const iframe = this.$refs.childIframe;
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
if (iframeDocument) {
const styleElement = iframeDocument.createElement('style');
styleElement.type = 'text/css';
const newStyles = `
#app .main-container {
margin-left: 0px !important;
}
#app .sidebar-container {
display: none !important;
}
.navbar {
display: none !important;
}
`;
styleElement.appendChild(iframeDocument.createTextNode(newStyles));
iframeDocument.head.appendChild(styleElement);
// iframe
iframe.style.display = 'block';
}
}
}
};
</script>
<style scoped>
</style>
Loading…
Cancel
Save