npm i @escook/request-miniprogram
// 在main.js
import {
$http
} from '@escook/request-miniprogram'
uni.$http = $http
// 配置请求根路径
$http.baseUrl = 'http://39.103.218.27/lixin'
// 请求开始之前做一些事情
const token = uni.getStorageSync('token');
options.header = {
token
}
uni.showLoading({
title: '数据加载中...',
})
// 请求完成之后做一些事情
$http.afterRequest = function() {
uni.hideLoading()
}
使用时
const
res = await uni.$http.post('接口', 参数)