npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cft-fetch

v0.0.4

Published

cheftin vueFetch

Downloads

4

Readme

cheftin vue fetch

对fetch API根据业务需要进行通用封装,解决了如下问题:

  1. 提供统一钩子函数, 方便统一加loading
  2. 提供响应数据拦截器,可在数据到达组建之前修改响应数据
  3. 提供两种缓存,session,对应sessionStorage, storage对应localStorage,解决重复调用的问题

Requirements

  • vue: ^2.0.0

Usage

Install

 npm install cft-fetch --save

Main.js


import vueFetch from 'vue-cft-fetch'

Vue.use(vueFetch, {
  beforeSendAll () {
    // 请求前勾子函数,如需调用vue实例上的方法,请使用this.$vm.xxx()
  },
  afterResponseAll (resp) {
    // 响应后勾子函数,如需调用vue实例上的方法,请使用this.$vm.xxx()
  },
  interceptor (resp) {
    // 拦截器,可对请求结果进行拦截修改,方便组件中使用async函数
    if (resp.status) {
      return resp.data
    } else {
      return resp
    }
  }
})

Options

url: url, *必填
params: params, *必填
type: GET, //默认 ‘GET’
session: false,
storage: false,
hook: true // 有些情况可能并不想触发全局请求钩子函数,把这个属性改为false即可, 默认为true
cros: false // 是否为跨域请求
beforeSend () {}, //请求发送前的钩子
afterResponse () {}, //响应成功的钩子
beforeSendAll () {}, //全局请求发送前的钩子, 其中的this指向插件本身,如需使用vue实例上的方法,请用this.$vm
afterResponseAll () {}, //全局响应成功的钩子,其中的this指向插件本身,如需使用vue实例上的方法,请用this.$vm
interceptor (resp) { // 拦截器,请求成功的时候,返回的数据会从拦截器穿过,可以做一些数据过滤
  return resp
}