增加postMessage传输token
This commit is contained in:
parent
07421d5b09
commit
c685b9f52a
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<iframe :src="iframeSrc" style="width: 100%; height: 100vh; border: none"></iframe>
|
||||
<iframe ref="mallFrame" :src="iframeSrc" style="width: 100%; height: 100vh; border: none"></iframe>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
|
@ -11,14 +11,27 @@ export default {
|
|||
}
|
||||
},
|
||||
mounted() {
|
||||
console.log('🚀 ~ mounted:', window.location)
|
||||
// 增加路由参数
|
||||
|
||||
// 构造 iframe 地址,使用相对路径自动携带Cookie
|
||||
this.iframeSrc =
|
||||
process.env.NODE_ENV === 'production'
|
||||
? '/iws/mall-view/home?redirect=equipList'
|
||||
: 'http://localhost:8102/iws/mall-view/home?redirect=equipList'
|
||||
console.log('🚀 ~ this.iframeSrc:', this.iframeSrc)
|
||||
|
||||
// 等 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>
|
||||
|
|
|
|||
Loading…
Reference in New Issue