请问我该怎么将接口返回的内容保存起来
用的 jssdk 登录界面,action 登录按钮 请求登录接口,登录接口返回 token 和 过期时间,这时我该怎么将 token 和 过期时间取到 并存储下来呢
放到store中存储
放到store中存储
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>AMIS Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<link rel="stylesheet" href="https://houtai.baidu.com/v2/csssdk">
<style>
html,
body,
.app-wrapper {
position: relative;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
@media screen and (min-width: 600px) {
.a-Page-body {
height: 500px;
display: flex;
justify-content: center;
align-items: center;
}
.a-Panel--form {
width: 555px;
}
}
</style>
</head>
<body>
<div id="root" class="app-wrapper"></div>
<script src="https://houtai.baidu.com/v2/jssdk"></script>
<script type="text/javascript">
var amis = amisRequire('amis/embed');
amis.embed('#root',
{
"$schema": "https://houtai.baidu.com/v2/schemas/page.json",
type: "page",
title: "管理系统",
body: [{
type: "form",
title: "XX管理系统",
mode: "horizontal",
controls: [
{
label: "用户名",
type: "text",
name: "name",
},
{
label: "密码",
type: "password",
name: "pwd",
}
],
className: "Login",
actions: [{
type: "action",
label: "登录",
level: "primary",
actionType: "ajax",
api: "/user/login",
redirect: "./index.html",
}]
}]
},
);
</script>
</body>
</html>
这是我的代码 ,感觉没地方写啊😂
最简单的方式是后端存 cookie,后续的每个接口都会带上。
最简单的方式是后端存 cookie,后续的每个接口都会带上。
谢谢 用这个方式暂时解决了登录问题,当携带token的 业务接口,token 过期 或 无效时,又该怎么重定向到登录页呢,实验了后端重定向,页面不跳转
如果接口返回 {status: 302, url: 'xxx'} 是可以重定向的。
不能重定向是因为 ajax 处理 302 时不会有作用,所以要返回 特定的 json 格式,前端做重定向。目前的约定是返回上面那个格式。
感谢 ,不过我没有尝试成功,不知道是哪里的问题 @2betop
不能重定向是因为 ajax 处理 302 时不会有作用,所以要返回 特定的 json 格式,前端做重定向。目前的约定是返回上面那个格式。
感谢 ,不过我没有尝试成功,不知道是哪里的问题 @2betop
不能重定向是因为 ajax 处理 302 时不会有作用,所以要返回 特定的 json 格式,前端做重定向。目前的约定是返回上面那个格式。
@2betop
不好意思,看来 sdk 版本没有加这个逻辑。
不好意思,看来 sdk 版本没有加这个逻辑。
好吧 谢谢您,请问近期有打算要加吗?没有的话 我得想想别的办法
线上的 sdk 版本一会更新。也就是说你用这个版本
有空的时候试试,应该可以了,没问题就关了这个
感谢
还是不行 我清楚缓存了 @2betop
我刚亲自试了,没问题的。你要不再试试?
生效了 谢谢大佬
生效了 谢谢大佬
你是用什么版本的解决问题呢?我现在用1.1.4,还是无法跳转。