1.不需要安装任何request插件
2.使用uni内部自带的http
一、根路径上配置个common/config.js common是文件夹
config.js的代码是
module.exports = {
//后端接口地址 您的后端接口 记得加端口
baseUrl: '',
// 超时
timeout: 30000,
// 禁用 Cookie 等信息
withCredentials: false,
header: {
//租户ID
'tenant-id': 1
}
}
api文件夹下的index.js封装,主要是get和post两种
//请求工具参考https://ext.dcloud.net.cn/plugin?id=392
const {
http
} = uni.$u
import config from '@/common/config'
const baseUrl = config.baseUrl
//
export const getDicts = params => http.post(baseUrl + '/方法', params)
//
export const getPhone = params => http.get(baseUrl + '/方法', { params })