Code Monkey home page Code Monkey logo

xyios's Introduction

控制缓存, 可配合支持promise的http插件使用,比如axios。

重点说一下, xyios不需要后台配合,简单粗暴。如果配合axios,不破坏原来的任何功能

Usage

import xyios from 'xyios'

let http = xyios(axios, {
  cacheTime: 10, 
  MaxCacheLen: 1000, 
  filtMethods: ['post'],
})

Or jsonp  (支持后面加参数)(支持var和callback函数)

xyios({
  url: 'http://pv.sohu.com/cityjson',
  jsonp: true,
  val: 'returnCitySN'
}).then(e=>{
  console.log(e)
})

配合axios和vue的实例

main.js全局注入

import xyios from 'xyios'
import axios from 'axios'

Vue.prototype.$http = xyios(axios, {
  cacheTime: 10, 
  MaxCacheLen: 1000, 
})

API

config

cacheTime // 缓存周期 默认是10s   单位是秒
MaxCacheLen // 最多缓存接口数 默认是1000条
filtMethods // 过滤不想要缓存的方法

jsonp

jsonp // true 调起jsonp模式
val 回调的值,链接字,看get接口里面的var的值,如果是函数也可以。

关于

axios的interceptors拦截器请写带xyios的前面

LICENSE

MIT

xyios's People

Contributors

0123cf avatar

Watchers

James Cloos 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.