wl-stations-http

用于 vue3 - vite
1,216
Install
npm install wl-stations-http
Latest Version:2.0.0
License:ISC
Last Updated:Sep 1, 2025
Links: npm
Maintainer: wang_lang

用于 vue3 - vite

Http 使用方法

注意,目前仅支持 post 和 get 方法

下载

//在控制台输入命令安装
npm i wl-stations-http

使用

// 构建http对象
let http = new Http({
  baseUrl: "", //请求基础路径
  serviceName: " ", //自服务的名称
  rpcUrl: " ", // psc节点的地址,不填则默认为 https://psc-mainnet.polysmartchain.com
  content: " ",
  signature: " ",
});

调用接口

http
  .post(`proposal/pip/proposal`, {
    pageNum: 1,
    pageSize: 10,
  })
  .then((res) => {
    console.log("响应结果", res);
  });

// or

let { data: res } = await http.post(`proposal/pip/proposal`, {
  pageNum: 1,
  pageSize: 10,
});

添加请求或响应拦截器 (可以添加多个)

// 添加请求拦截器
http.addRequestInterceptor((config) => {
  /*
  let config = {
      method: "POST",
      headers: { "Content-Type": "application/json", ...headers },
      body: JSON.stringify(params),
      url: await this.initUrl(path),
    };
  */
  if (config.url.includes("/api/points")) {
    config.baseURL = "https://burnrate.polysmartchain.com";
  }
  if (token) {
    config.headers = {
      authorization: token,
    };
  }
  return config;
});

//响应拦截器 参数同上
// http.addResponseInterceptor(config=>{});

桥接 使用方法

Version History

Version Released License
2.0.0 ISC
1.1.13 ISC
1.1.12 ISC
1.1.11 ISC
1.1.10 ISC