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

data-request

v1.1.1

Published

数据请求封装

Downloads

2

Readme

数据请求

参数泛型:

T: params参数类型 R: 返回数据类型 D: data数据类型

参数释义:

| 参数名 | 参数类型 | 参数描述 | | :---------: | :-----------------: | :------: | | url | string | 接口url | | params | T | 参数 | | data | D | body传值 | | timeout | number | undefined | 超时时间 |

方法描述:

| 方法名 | 携带泛型 | 参数 | 方法描述 | | :---------------: | :------: | :---------------: | :--------: | | getRequest | R,T | url,params,timeout | get请求 | | deleteRequest | R,T | url,params,timeout | delete请求 | | postRequest | R, D, T | url,data,params,timeout | post请求 | | putRequest | R, D, T | url,data,params,timeout | put请求 | | patchRequest | R, D, T | url,data,params,timeout | patch请求 |

设计描述:

1. 为什么单例中要求传入Axios实例?

源代码单例截图:

image-20200902172538792

传入的request是当前项目进行的基础的axios封装,比如拦截器,鉴于项目的不同,后期更新的不同,基础封装的axios作为参数传入。

request文件示例:

import axios from "axios";
const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API // url = base url + request url
});

// Request interceptors
service.interceptors.request.use(
  config => {
    // // Add Authorization header to every request, you can add other custom headers here
    // if (UserModule.token) {
    //   config.headers["Authorization"] = `Bearer ${UserModule.token}`;
    // }
      ...//
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

// Response interceptors
service.interceptors.response.use(
  response => {
    if (response.status === 200) {
      return response.data;
    } else {
        ...//
      console.error(`request failed error: ${response}`);
    }
  },
  error => {
    const response = error.response;
    ....//
    return Promise.reject(error);
  }
);

export default service;

2. 项目如何引用

2.1 安装插件
npm i data-request --save
2.2 引入使用

image-20200902173547131

在业务的入口管理处进行定义。

使用示例:

image-20200903140859808