feat: 相同顶级域名不同子域名共享cookie

master
LCJ-MinYa 11 months ago
parent c91cdeaa92
commit 5c07d8461c

@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<title>cookie</title>
</head>
<body>
<div>我是cookie.test.com:52330设置cookie页面</div>
</body>
</html>
<script>
document.cookie = 'test-Cookie=我是测试相同顶级域名下不同子域名之间是否能共享cookie; domain=test.com; path=/; SameSite=Strict';
</script>

@ -52,6 +52,10 @@ const titleArr = [
key: 'iframeEvent',
title: 'iframe页面的事件监听',
},
{
key: 'cookie',
title: '相同顶级域名不同子域名共享cookie',
},
];
// @/views/demo/**/*.vue

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

@ -0,0 +1,27 @@
<template>
<div>
<div>我是mgt.test.com:8848获取cookie页面</div>
<div>通过控制台查看cookie</div>
<img src="./img/1.png" />
<img src="./img/2.png" />
<img src="./img/3.png" />
<img src="./img/4.png" />
<img src="./img/5.png" />
</div>
</template>
<script setup>
import Cookies from 'js-cookie';
/**
* 1. 首先需要通过hosts设置域名映射(设置后需要刷新dns, mac命令`sudo killall -HUP mDNSResponder`)
* 127.0.0.1 mgt.test.com
* 127.0.0.1 cookie.test.com
*
* 2. 通过vscode启动/demoHtml/cookie.html本地服务然后通过http://cookie.test.com:52330/demoHtml/cookie.html访cookie
* 52330这个端口每次不一样是vscode动态生成的
*
* 3. 最后启动该项目然后通过http://mgt.test.com:8848/#/demo/cookie访cookie
*/
console.log('test-Cookie', Cookies.get('test-Cookie'));
</script>

@ -1,5 +1,6 @@
<template>
<div class="iframe-event">
<!-- 同源iframe嵌入页面 -->
<iframe
id="iframe1"
src="/demoHtml/iframe.html"
@ -8,6 +9,7 @@
height="300"
/>
<!-- 下面这个地址是使用的vscode启动的本地服务每次需要手动修改和修改该地址这里是为了模拟跨域情况 --->
<!-- 跨域iframe嵌入页面 -->
<iframe
id="iframe2"
src="http://localhost:52330/demoHtml/iframe.html"

Loading…
Cancel
Save