增加postMessage传输token

This commit is contained in:
syruan 2025-12-17 09:04:38 +08:00
parent 07421d5b09
commit c685b9f52a
1 changed files with 18 additions and 5 deletions

View File

@ -1,5 +1,5 @@
<template> <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> </template>
<script> <script>
@ -11,14 +11,27 @@ export default {
} }
}, },
mounted() { mounted() {
console.log('🚀 ~ mounted:', window.location) // iframe 使Cookie
//
this.iframeSrc = this.iframeSrc =
process.env.NODE_ENV === 'production' process.env.NODE_ENV === 'production'
? '/iws/mall-view/home?redirect=equipList' ? '/iws/mall-view/home?redirect=equipList'
: 'http://localhost:8102/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> </script>