Cookies
获取请求头 cookies 信息
设置响应头 cookies 信息
ts
import { defineMock } from 'vite-plugin-mock-dev-server'
export default defineMock([
{
url: '/api/login',
cookies: {
token: 'username&password',
},
body: {
code: 200,
message: 'login success',
},
},
{
url: '/api/logout',
cookies({ getCookie }) {
const token = getCookie('token')
if (token) {
return {
token: ['', { expires: new Date(Date.now() - 86400000) }],
}
}
return {} as any
},
body: {
code: 200,
message: 'logout success',
},
},
{
url: '/api/check-login',
body(request) {
const token = request.getCookie('token')
return {
isLogin: !!token,
}
},
},
])
import { defineMock } from 'vite-plugin-mock-dev-server'
export default defineMock([
{
url: '/api/login',
cookies: {
token: 'username&password',
},
body: {
code: 200,
message: 'login success',
},
},
{
url: '/api/logout',
cookies({ getCookie }) {
const token = getCookie('token')
if (token) {
return {
token: ['', { expires: new Date(Date.now() - 86400000) }],
}
}
return {} as any
},
body: {
code: 200,
message: 'logout success',
},
},
{
url: '/api/check-login',
body(request) {
const token = request.getCookie('token')
return {
isLogin: !!token,
}
},
},
])
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39