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 🙏

© 2026 – Pkg Stats / Ryan Hefner

uni-http-interface

v0.0.6

Published

uniapp请求拦截

Downloads

7

Readme

uni-http-interface

使用方法

第一步:配置封装拦截器和基础路径:http.js

import http from 'uni-http-interface';

// 公共配置项,三种api通用
http.config = {
	baseUrl: 'http://baidu.com', // 基础路径
	timeout: 6000, // 超时时间
}
// 对应接口配置项
http.requestConfig {
	// uni.request(OBJECT)的 OBJECT 参数: https://uniapp.dcloud.io/api/request/request.html#request
	...
}
http.uploadFileConfig {
	// uni.uploadFile(OBJECT)的 OBJECT 参数: https://uniapp.dcloud.io/api/request/network-file.html#uploadfile
	...
}
http.downloadFileConfig {
	// uni.downloadFile(OBJECT)的 OBJECT 参数: https://uniapp.dcloud.io/api/request/network-file.html#downloadfile
	...
}

http.interceptor.invoke = config => {
	// 请求拦截前触发
	return config
}

http.interceptor.success = res => {
	// 请求成功回调拦截
	// 成功回调
	return Promise.resolve(response.data)
	// 走失败回调
	return Promise.reject(response)
}

http.interceptor.fail = err => {
	// 请求失败回调拦截
	// 走失败回调
	return Promise.reject(response)
}

http.interceptor.complete = res => {
	// 请求完成回调拦截
	// 成功回调
	return Promise.resolve(response.data)
	// 走失败回调
	return Promise.reject(response)
}

// 已封装:get,post,put,delete,upload,download请求,如需其他请求自行在下方封装

export default http

第二步:使用http.js

import http from '@/utils/http'
// 接口请求拦截
let interceptor = {
	invoke: config => {
		// 请求拦截前触发,同:http.interceptor.invoke,该配置存在会最终取该配置的参数
		return config
	},
	success: response => {
		// 请求拦截前触发,同:http.interceptor.success,该配置存在会优先执行
	    // 请求成功回调拦截
	    // 成功回调
	    return Promise.resolve(response.data)
	    // 走失败回调
	    return Promise.reject(response)
	},
	fail: error => {
		// 请求拦截前触发,同:http.interceptor.fail,该配置存在会优先执行
	    // 走失败回调
	    return Promise.reject(error)
	},
	complete: response => {
		// 请求拦截前触发,同:http.interceptor.complete,该配置存在会优先执行
	    // 请求成功回调拦截
	    // 成功回调
	    return Promise.resolve(response.data)
	    // 走失败回调
	    return Promise.reject(response)
	}
}
// 请求的参数
let data = {
	...,
}
// OBJECT参数
let option = {
	...,
}
// 发出get请求
http.get('/user/userInfo', data, option, interceptor)
// 发出post请求
http.post('/user/login', data option, interceptor)
// 发出put请求
http.put('/user/userInfo', data option, interceptor)
// 发出delete请求
http.delete('/user/userInfo', data option, interceptor)
// 上传文件请求
http.upload('/upload/file', {
	file, // 上传文件字段,三选一即可:https://uniapp.dcloud.io/api/request/network-file.html#uploadfile
	...option // option参数
}, interceptor)
// 下载文件
http.download('/download/file', option, interceptor)