项目作者: qq4917220

项目描述 :
weex-session是一个session代替的中间件,可用来替换local-storage,方便使用,且不占资源。Weex-session is a session replacement middleware that can be used to replace local-storage, easy to use, and not to take up resources.
高级语言: JavaScript
项目地址: git://github.com/qq4917220/weex-session.git
创建时间: 2018-01-12T03:17:40Z
项目社区:https://github.com/qq4917220/weex-session

开源协议:

下载


Weex-session is a session replacement middleware that can be used to replace local-storage, easy to use, and not to take up resources.

Thanks to Zaaksam’s technology sharing!

weex-session是一个session代替的中间件,可用来替换local-storage,方便使用,且不占资源。

感谢Zaaksam的技术分享!

Install

npm install weex-session --save

Usage

  1. import session from "weex-session";

Options

  • set<T>(key: string, value: T) 设置session,需要传值的类型 set the session, need to pass the type of value
  • get<T>(key: string) 获取session get session
  • content 全部记录内容 all records
  • keys 全部记录的键值数组 All recorded array of key values
  • has(key: string) 是否存在这个key whether the existence of this key
  • del(key: string) 删除这个key delete this key
  • reset() 清空全部记录 clear all the records

Example

  1. session.set<string>("str", "string");
  2. session.set<number>("num", 100);
  3. this.content += "str:" + session.get("str") + "<br/>";
  4. this.content += "num:" + session.get("num") + "<br/>";
  5. this.content += "content:" + JSON.stringify(session.content()) + "<br/>";
  6. session.del("str");
  7. session.del("num");
  8. this.content +=
  9. "content is clear:" + JSON.stringify(session.content()) + "<br/>";
  10. session.set<string>("str", "string");
  11. session.set<number>("num", 200);
  12. this.content +=
  13. "content show keys:" + JSON.stringify(session.keys()) + "<br/>";
  14. session.reset();
  15. this.content +=
  16. "content is reset:" + JSON.stringify(session.content()) + "<br/>";

Result

  1. -----------run-------------
  2. str:string
  3. num:100
  4. content:{"str":"string","num":100}
  5. content is clear:{}
  6. content show keys:["str","num"]
  7. content is reset:{}
  8. -----------END run-------------

Other

生成的JS文件在dist目录中,可使用JS调用,调用方式雷同,不再重复。

The generated JS file can be called in the dist directory using the JS call, and the call is identical and no longer repeats.

Licences

[MIT]