|
|
3 hours ago | |
|---|---|---|
| .. | ||
| README.md | 3 hours ago | |
| env.development.js | 3 hours ago | |
| env.production.js | 3 hours ago | |
| index.js | 3 hours ago | |
config/
├── index.js # 配置入口
├── env.development.js # 开发环境
├── env.test.js # 测试环境
├── env.production.js # 生产环境
└── README.md # 使用说明
编辑 config/index.js 文件,修改 CURRENT_ENV 变量:
// 手动修改此处切换环境:development | test | production
const CURRENT_ENV = 'development'
每个环境文件包含以下配置:
| 配置项 | 类型 | 说明 |
|---|---|---|
env |
string | 环境标识 |
baseUrl |
string | API 基础地址 |
timeout |
number | 请求超时时间 (ms) |
appName |
string | 应用名称 |
appVersion |
string | 应用版本 |
appId |
string | 微信小程序 AppID |
debug |
boolean | 是否开启调试模式 |
enableLog |
boolean | 是否打印日志 |
<script setup>
import config from '@/config/index.js'
// 直接访问配置
console.log('API 地址:', config.baseUrl)
console.log('应用名称:', config.appName)
console.log('AppID:', config.appId)
</script>
import config from '@/config/index.js'
console.log(config.baseUrl)
console.log(config.appName)
import request from '@/utils/request.js'
// 会自动使用对应环境的 baseUrl
await request.post('/api/auth/login', data)
import { CURRENT_ENV } from '@/config/index.js'
console.log('当前环境:', CURRENT_ENV)
编辑对应的环境文件,例如 config/env.development.js:
export default {
env: 'development',
baseUrl: 'https://dev-api.example.com', // 修改 API 地址
timeout: 10000,
appName: '布尔销销乐',
appVersion: '1.0.0',
appId: 'wx6124d881774fb80a',
debug: true,
enableLog: true
}
import(),使用同步导入CURRENT_ENV 配置错误,会自动使用开发环境配置