This package has been deprecated

Author message:

这个package废弃了, 请使用 axios + axios-plugins 来满足微信环境下使用通用请求库的需要

wx-req
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

微信 request 请求封装

1. 支持功能

参考 axios 实现, 使用方式上跟 axios 差不多.

新增云函数支持

2. use

 import { Request } from "wx-conn"; // import

 // instantiation
 let request = new Request({...your config});

 // use
 request.executeRequest({
     method:...,
     url:...,
     data:...
 }).[then or catch];

 // single use

 request.get(url,data,options?).[then or catch]

 // global use

 global.request = request; // demo 1

 // or push request to global properties.

note

  1. 请求预处理跟 response 解析尽量封装为公共方法,放到 transfromRequest 和 transformResponse 中处理

  2. 云函数返回值, 云函数返回值要加壳,跟 request 请求后端拿到返回值尽量一致,这样可以省去一些返回值解析上面的麻烦

  3. 如果确认不一致的情况下, 建议在 transformResponse 中,单独加一个云函数结果解析器.根据 requestOptions 判断

  4. cookies 功能写出来以后我没测试过,尽量不要用。

  5. 注意,编译 npm 的时候云函数在当前项目目录下,会被编译进去.导致 miniprogram_module 过大 参考:https://developers.weixin.qq.com/community/develop/doc/000e241879cfd852c06ab6fd956c00

  6. 真机运行如果出现 wx-req 加载失败情况, 将引用路径换成 miniprogram_module 下的绝对路径即可.微信小程序加载机制有代码大小检查,我在另外一个项目上出过这个问题.

Package Sidebar

Install

npm i wx-req

Weekly Downloads

1

Version

1.0.5

License

Apache-2.0

Unpacked Size

808 kB

Total Files

52

Last publish

Collaborators

  • halo-951