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-request-method

v0.0.18

Published

this is a project of send axios request

Downloads

39

Readme

serviceAPI 说明文档

业务痛点:在现有多业务场景下,经常出现书写业务代码捕获后端异常的时候因为考虑不全而导致页面出现一系列的问题。基于这个痛点,对请求api进行统一封装,统一处理,减少前端冗余代码,减少前端对后端错误信息的关注度,从而更好的把精力应用于业务开发。 依赖:依赖于axios 支持:内置基于sucess字段进行错误处理,如果需要更改条件,则可以更改初始化时传入的逻辑处理字段,也可自定义错误处理细节

/**
 * @param {object} baseConfig  应用基础配置
 * @param {string}  [baseConfig.baseUrl]  baseUrl,请求base,必传
 * @param {string}  [baseConfig.mockUrl] mock环境下请求baseUrl,非必传
 * @param {boolean}  [baseConfig.mock] 是否为mock环境,非必传
 * @param {boolean}  [baseConfig.local] 是否为本地,非必传
 * @param {number}  [baseConfig.timeout] 超时时间,默认5s,非必传
 * @param {function}  [baseConfig.errorHandler]  默认错误处理逻辑,非必传(优先级4)
 * @param {function}  [baseConfig.customizeCallback]  默认数据处理逻辑(优先级2),非必传(第一个参数为响应体,第二个为successCallback, 第三个为failCallbackaa)
 * @param {boolean}  [baseConfig.mixin]  是否需要全局混入方法 非必传
 * @param {object}  [baseConfig.headers] // 默认请求头  非必传
 * @return {function}
 *  * @param {object} params 
 * @param {string}  [params.url] service Api 请求url 必填
 * @param {string}  [params .methods]  请求方法 必填
 * @param {string}  [params .params]  queryString 非必填
 * @param {object}  [params .data]  请求体, 非必填
 * @param {string}  [params .loadingName] 控制loading字段 , 非必填
 * @param {function}  [params .successCallback] 成功回调, 非必填
 * @param {function}  [params .failCallback]  失败回调, 非必填(优先级3)
 * @param {function}  [params .customizeCallback] 自定义错误处理(优先级1),非必填,兼容不规范接口
 * @param {object}  [baseConfig.headers] 请求头设置, 非必填
 */
// main.js, mixin为true的实例
import baseUrl from './plugin/lib/CheckItemManage/src/api/host';
import request from '@ennbmp/axios-request-method';
Vue.use(request({
  baseUrl: baseUrl.host,
  mixin: true,
  headers: {
    'X-GW-AccessKey': '*******',
    ticket: sessionStorage.getItem('ticket') || '',
  },
}));
// test.js
export default {
	methods: {
	async	getTemplate() {
      		  const result = await  this.$sendRequest({
        	    	url: '/bmp-elec-config-bff/device/template/list',
        	    	methods: 'get',
        	    	data: {
          	    			entId: sessionStorage.getItem('entId'),
       		    	},
        	    	loadingName: 'templateLoading',
        	    	successCallback: data => {
          	    			this.templateList = data;
        	    	},
      		    });
                  // result也可以拿到返回结果
            console.log(result);
    	},
	}
}
// main.js mixin 为false的实例
import baseUrl from './plugin/lib/CheckItemManage/src/api/host';
import request from 'axios-request-method';
Vue.use(request({
  baseUrl: baseUrl.host,
  mixin: false,
  headers: {
    'X-GW-AccessKey': 'yiUMxMZ3yimP8Pjh0W8ffyuNvTpz59ry',
    ticket: sessionStorage.getItem('ticket') || '',
  },
}));
// test.js
// test.js
export default {
	methods: {
	// 需要自己去控制loading
		this.$service({
        	url: '/bmp-elec-config-bff/device/template/list',
        	methods: 'get',
        	data: {
          		entId: sessionStorage.getItem('entId'),
        	},
        	successCallback: data => {
          		this.templateList = data;
        	},
      });
	}
}

0.0.14添加取消无效请求

0.0.15下掉无用提示

0.0.16 增加async支持

0.0.18 优化对重复请求的判断逻辑,防止同样url不同参数的请求被截断,下掉code 200逻辑