bonus-ui/src/views/iframe/MallIframe.vue

38 lines
971 B
Vue
Raw Normal View History

2025-10-13 18:28:18 +08:00
<template>
2025-12-17 09:04:38 +08:00
<iframe ref="mallFrame" :src="iframeSrc" style="width: 100%; height: 100vh; border: none"></iframe>
2025-10-13 18:28:18 +08:00
</template>
2025-10-22 13:31:23 +08:00
<script>
export default {
name: 'MallIframe',
data() {
return {
iframeSrc: '',
}
},
mounted() {
2025-12-17 09:04:38 +08:00
// 构造 iframe 地址使用相对路径自动携带Cookie
2025-10-22 13:31:23 +08:00
this.iframeSrc =
process.env.NODE_ENV === 'production'
2025-12-16 16:55:51 +08:00
? '/iws/mall-view/home?redirect=equipList'
2025-11-18 14:09:29 +08:00
: 'http://localhost:8102/iws/mall-view/home?redirect=equipList'
2025-12-17 09:04:38 +08:00
// 等 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
)
}
}
2025-10-22 13:31:23 +08:00
},
}
</script>