更新Pinia store中的token
This commit is contained in:
parent
6035372b02
commit
8f8b096baf
|
|
@ -22,9 +22,14 @@ const handleMessage = (event: MessageEvent) => {
|
|||
console.log('B项目收到来自A项目的token')
|
||||
|
||||
if (token && typeof token === 'string') {
|
||||
// 将token存储到localStorage,供axios拦截器使用
|
||||
// 1. 将token存储到localStorage,供axios拦截器使用
|
||||
localStorage.setItem('tokenNew', token)
|
||||
console.log('Token已成功保存到localStorage,后续请求将自动携带Authorization头')
|
||||
|
||||
// 2. 同步更新Pinia store中的token(重要!路由守卫需要检查这个)
|
||||
userStore.setToken(token)
|
||||
|
||||
console.log('✅ Token已成功保存到localStorage和Pinia store')
|
||||
console.log('✅ 后续请求将自动携带Authorization头,路由守卫也会放行')
|
||||
|
||||
// 可选:向A项目发送确认消息
|
||||
if (event.source && typeof event.source.postMessage === 'function') {
|
||||
|
|
|
|||
|
|
@ -98,10 +98,6 @@
|
|||
</div>
|
||||
</div>
|
||||
<div style="text-align: right">
|
||||
<!-- <el-button type="primary" round icon="ChatDotRound">在线聊</el-button> -->
|
||||
<el-button type="primary" class="primary-lease" round icon="ChatDotRound"
|
||||
>在线聊</el-button
|
||||
>
|
||||
</div>
|
||||
<div style="text-align: right">
|
||||
<el-button
|
||||
|
|
|
|||
Loading…
Reference in New Issue