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

vaxios-plugin

v0.1.8

Published

二次封装 axios,使 vue.js 中使用 axios 变得更加简单

Readme

vaxios-plugin

NPM version GitHub forks GitHub stars NPM download GitHub license

二次封装 axios,使 vue.js 中使用 axios 变得更加简单

特点

  • 遵循 RESTful
  • 支持 await
  • 支持 async
  • 简单易用

Install

npm i -S vaxios-plugin

param

$GET

GET 原则上是不可以发一个带有 Body 的请求包,但是 HTTP 规范上并没有规定 GET 不可以发一个带有 Body 的请求包,在 axios 中虽然也支持发一个带有 Body 的请求包,本插件也集成了,但是如果后端不支持的话,慎用

/**

  • [$GET 全局的 GET 方法]
  • @method $GET
  • @param {String} url RESTful URL
  • @param {Object} payload GET 的 body 参数 */

$POST

/**

  • [$POST 全局的 POST 方法]
  • @method $POST
  • @param {String} url RESTful URL
  • @param {Object | Array} payload POST 的 body 参数 */

$PUT

/**

  • [$PUT 全局的 PUT 方法]
  • @method $PUT
  • @param {String} url RESTful URL
  • @param {Object | Array} payload PUT 的 body 参数 */

$PATCH

/**

  • [$PATCH 全局的 PATCH 方法]
  • @method $PATCH
  • @param {String} url RESTful URL
  • @param {Object | Array} payload PATCH 的 body 参数 */

$DELETE

/**

  • [$DELETE 全局的 DELETE 方法]
  • @method $DELETE
  • @param {String} url RESTful URL
  • @param {Object} payload DELETE 的 body 参数 */

Used

main.js

import Vue from 'vue'
import Vaxios from 'vaxios-plugin'

Vue.use(Vaxios, {
  useparam: true,
  param: {
    baseURL: 'https://cnodejs.org/api/v1',
    timeout: 0
  }
})

options

option | type | default | description ---------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- method | function | null | 自定义 axios 拦截方法,如果有自定义的方法,推荐设置自定义的拦截方法 throwError | object | { get_debug: false,post_debug: false,put_debug: false,patch_debug: false,delete_debug: false } | 当然可以直接使用 Boolean 值进行全部开启和全部关闭,该作用是在控制台中输出请求到的数据 useparam | boolean | false | 如果不想自定义 axios 拦截方法,该参数必须为 true param | object | { baseURL: 'http://127.0.0.1:8080/api',timeout: 0 } | 自定义 axios 拦截参数 |

在 vue 中使用

<script>
export default {
  methods: {
    get () {
      const url = `/users?id=123` // 必填
      this.$Get(url).then((data) => {
        console.log(data)
      })
    },
    post () {
      const url = `/users` // 必填
      const payload = {
        id: 123,
        username: 'admin',
        pwd: 'admin'
      } // payload 必须为 Object 或者 Array,必填

      this.$POST(url,payload).then((data) => {
        console.log(data)
      })
    }
  },
  put () {
    const url = `/users`
    const payload = {
      id: 123,
      username: 'admin',
      pwd: 'admin'
    } // payload 必须为 Object 或者 Array,必填

    this.$PUT(url,payload).then((data) => {
      console.log(data)
    })
  },
  patch () {
    const url = `/users/pwd`
    const payload = {
      pwd: 'admin',
      pwd2: 'admin'
    } // payload 必须为 Object 或者 Array,必填

    this.$PATCH(url,payload).then((data) => {
      console.log(data)
    })
  },
  deleteById () {
    const url = `/users/1`
    this.$DELETE(url).then((data) => {
      console.log(data)
    })
  },
  deleteByPayload (){
    const url = `/users`
    const payload = {
      id: [1,2,3,4]
    } // payload 必须为 Object 或者 Array,非必填

    this.$DELETE(url,payload).then((data) => {
      console.log(data)
    })
  }
}
</script>

axios 拦截的一个实例

import axios from 'axios'
import store from '@/store'
import config from '@/config'
import router from '@/router'
import {
  Message
} from 'element-ui'

const protocol = window.location.protocol
const host = window.location.host
const domain = document.domain
let serverURL = ''

if (domain === '127.0.0.1' || domain === 'localhost') {
  serverURL = config.serverURL
} else {
  serverURL = `${protocol}` + '//' + `${host}:8888/api`
}

// 创建 axios 实例
const instance = axios.create({
  baseURL: serverURL,
  timeout: 0
})

// http request 拦截器
instance.interceptors.request.use(
  config => {
    // 在 headers 头上添加参数
    config.headers['Content-Type'] = 'application/json;charset=UTF-8'
    if (store.state.auth.authToken) {
      config.headers['Authorization'] = `${store.state.auth.authToken}`
    }
    return config
  },
  error => {
    return Promise.reject(error)
  }
)

// http response 拦截器
instance.interceptors.response.use(
  response => {
    return response
  },
  error => {
    if (error.response) {
      const err = error.response.data
      switch (err.status) {
        case 401:
          Message({
            type: 'waring',
            message: err.message
          })
          setTimeout(() => {
            store.dispatch('logout')
            router.replace({
              name: 'Login'
            })
          }, 500)
          break
        case 404:
          Message({
            type: 'waring',
            message: err.message
          })
          setTimeout(() => {
            router.replace({
              name: 'NotFound'
            })
          }, 500)
          break
        case 422:
          Message({
            type: 'waring',
            message: err.message
          })
          break
        case 500:
          Message({
            type: 'error',
            message: err.message
          })
          break
        default:
          Message({
            type: 'error',
            message: err.message
          })
          break
      }
    }

    return Promise.reject(error)
  }
)

export default instance