38 lines
971 B
Vue
38 lines
971 B
Vue
<template>
|
||
<iframe ref="mallFrame" :src="iframeSrc" style="width: 100%; height: 100vh; border: none"></iframe>
|
||
</template>
|
||
|
||
<script>
|
||
export default {
|
||
name: 'MallIframe',
|
||
data() {
|
||
return {
|
||
iframeSrc: '',
|
||
}
|
||
},
|
||
mounted() {
|
||
// 构造 iframe 地址,使用相对路径自动携带Cookie
|
||
this.iframeSrc =
|
||
process.env.NODE_ENV === 'production'
|
||
? '/iws/mall-view/home?redirect=equipList'
|
||
: 'http://localhost:8102/iws/mall-view/home?redirect=equipList'
|
||
|
||
// 等 iframe 加载完成再传 token
|
||
this.$refs.mallFrame.onload = () => {
|
||
const token = localStorage.getItem('token') // A 项目的 token
|
||
console.log('A项目token:', token)
|
||
if (token) {
|
||
// 使用 postMessage 发送给 B
|
||
this.$refs.mallFrame.contentWindow.postMessage(
|
||
{
|
||
type: 'SET_TOKEN',
|
||
token: token,
|
||
},
|
||
window.location.origin
|
||
)
|
||
}
|
||
}
|
||
},
|
||
}
|
||
</script>
|