index.js 622 B

12345678910111213141516171819202122232425
  1. import config from '@/config.js'
  2. import defaultConfig from './defaultConfig.js'
  3. // 合并用户配置和默认配置
  4. const mergeConfig = Object.assign({}, defaultConfig, config)
  5. /**
  6. * 配置文件工具类
  7. * mix: 如需在项目中获取配置项, 请使用本工具类的方法, 不要直接import根目录的config.js
  8. */
  9. export default {
  10. // 获取全部配置
  11. all() {
  12. return mergeConfig
  13. },
  14. // 获取指定配置
  15. get(key, def = undefined) {
  16. if (mergeConfig.hasOwnProperty(key)) {
  17. return mergeConfig[key]
  18. }
  19. console.error(`检测到不存在的配置项: ${key}`)
  20. return def
  21. }
  22. }