Skip to content

请求配置

ucs-request 请求库的全局自定义配置项

配置项

osRequest

  • 类型:UTSJSONObject

  • 可选值:

类型描述兼容性
developmentstring测试环境-请求的前缀APP / Web / 微信小程序 / 支付宝小程序 / QQ小程序 / 快手小程序
productionstring正式环境-请求的前缀
logstring请求是否输出日志
dataUTSJSONObject默认请求的参数
headerUTSJSONObject默认请求的 header
timeoutnumber超时时间,单位 ms
withCredentialsboolean跨域请求时是否携带凭证(cookies)微信小程序 / Web
firstIpv4booleanDNS解析时优先使用ipv4微信小程序
enableChunkedboolean开启 transfer-encoding chunked。

使用演示

温馨提示

标准基座 / 自定义基座 编译运行时请求库前缀拼接采用的是 development 测试环境地址,正式打包编译采用的则是 production 正式环境地址

例如开发者需要配置请求属性,则只需要设置 osRequest 配置

ts
// ucsDefineConfig.uts
import { defineConfig } from "@/uni_modules/ucs-config";

defineConfig({
	// 配置项,需要哪项配置则配置哪项,这里作为演示则将所有配置项列出,开发者请根据实际需求配置
	osRequest: {
		// 测试环境
		development: "https://xxxxx.com",
		// 正式环境
		production: "https://xxxxxx.com",
		// 是否启用日志
		log: true,
		header: {
			'Content-Type': 'application/x-www-form-urlencoded', // POST表单请求
		},
		timeout: 60000,
		withCredentials: false,
		firstIpv4: false,
		enableChunked: false
	}
});