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

axios-uniapp

v0.0.2

Published

## 介绍

Downloads

1

Readme

axios-uniapp (typescript)

介绍

uniapp版axios封装,核心请求相关代码使用的是uni的request、upload和download方法,整体上用法和axios相同,适当做了一些代码缩减。 其中像get、post请求这些和axios用法一样,新增了upload上传和download下载的方法对应uni.upload、uni.download

安装

npm install --save-dev axios-uniapp

使用方法

拦截器

import axios from 'axios-uniapp'
const defaultConfig = {
  baseURL: '/api'
}
const instance = axios.create(defaultConfig)
instance.interceptors.request.use(config => {
  config.headers.token = 'xxxx'
  return config
})
instance.interceptors.response.use(response => {
  return response
})

请求

axios.get('/api/getUser', {
  params: {
    userId: 1
  },
  timeout: 1000 * 5
})

axios.post(
  '/api/addUser',
  {
    name: '小明',
    age: 10,
    sex: 1
  },
  {
    headers: {
      'Content-Type': 'application/json'
    },
    timeout: 1000 * 5
  }
)

axios({
  url: '/api/getUser',
  method: 'get',
  params: {
    userId: 1
  },
  timeout: 1000 * 5
})

上传、下载

axios.upload('/api/setUserAvatar', {
  // 上传相关配置项upload
  upload: {
    // files: 	Array	是(files和filePath选其一)	需要上传的文件列表。使用files时,filePath和name不生效。App、H5( 2.6.15+)
    // fileType:	String	见平台差异说明 文件类型,image/video/audio仅支付宝小程序,且必填。
    // file:	File	否	要上传的文件对象。	仅H5(2.6.15+)支持
    // filePath:	String	是(files和filePath选其一)要上传文件资源的路径。
    // name:	String	是	文件对应的key,开发者在服务器端通过这个key可以获取到文件二进制内容
  },
  onUploadProgress(e) {
    // 上传进度
    console.log(e.progress)
  }
})

axios.download('/api/exportExcel', {
  // 下载相关配置项download
  download: {
    // filePath	string	否	指定文件下载后存储的路径 (本地路径)
  },
  onDownloadProgress(e) {
    // 下载进度
    console.log(e.progress)
  }
})

axios({
  url: '/api/setUserAvatar',
  method: 'upload',
  upload: {
    name: 'file',
    filePath: res.tempFiles[0].path,
    formData: {}
  },
  onUploadProgress(e) {
    console.log(e.progress)
  }
})