GithubHelp home page GithubHelp logo

diycp / ajax-data-model Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lzwme/ajax-data-model

0.0 1.0 0.0 95 KB

ajax 通用数据请求处理模型。提供 ajax 请求、数据缓存、通用性接口约定处理等功能

Home Page: https://lzw.me/pages/demo/ajax-data-model/api/

License: MIT License

HTML 1.27% JavaScript 98.73%

ajax-data-model's Introduction

Ajax-Data-Model

NPM version Dependency Status License Downloads

ajax 通用数据请求处理模型。在 ajax 请求的生命周期过程中,处理通用的约定行为操作。

特性

  • umd 支持
  • memory/sessionStorage/localStorage 级数据缓存支持
  • Promise thenable 风格的 API 调用
  • 基于接口约定的通用回调处理支持(通用错误处理、loading 状态、通用参数、埋点上报<接口超时、接口错误、接口异常、数据埋点等>...)

快速开始

下载安装

手动下载:到代码仓库下载 release 的 zip 包,取得 dist 目录内文件即可。

npm 方式:

npm i --save ajax-data-model

使用

ES6 方式使用

  1. 全局性设置
// adm.js
import $ from 'jquery';
import adm from 'ajax-data-model';
// 全局性设置
adm.setSettings({...});

adm.restapi = {
  userlist: '/rest/user/list'
};
// todo more...

export default adm;

具体参考 src/common/settings.js 中的参数配置示例。

  1. 使用
import adm from './adm';
// 使用示例
adm.get({url: '/xxx'}).then((result) => {
  console.log(result);
});

直接引用使用:

  1. 引入 jquery 和 js
<script src="lib/jquery/juqery.min.js"></script>
<script src="lib/ajax-data-model/adm.jquery.min.js"></script>
  1. 使用
<script>
  // 全局性设置
  adm.setSettings({...});
  // 使用
  adm.get({url: '/xxx'}).then((result) => {
    console.log(result);
  });
</script>

命令脚本与二次开发

  • npm start - 开启 3131 端口 web 服务,进行测试开发。
  • npm run dev - 开启开发监听模式,监听 src 目录。
  • npm test - mocha + chai 测试(需先执行 npm start)。
  • npm run build - 构建生产环境使用源码 (mini) 到 lib 目录。
  • npm run jsdoc - 生成 jsdoc 风格的 API 文档。

API

参阅: API

更多示例:USEAGE.md

License

ajax-data-model is released under the MIT license.

该插件由志文工作室开发和维护。

ajax-data-model's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.