buddhism/common/http.config.js
minimaxagent1 5d3031d9f0 页面级别Loading管理
统一使用新的request工具
2025-08-02 10:35:11 +08:00

53 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// HTTP配置文件 - 替代 http.interceptor.js
import { setRequestConfig, getRequestConfig } from '@/utils/request.js'
/**
* 初始化HTTP配置
* @param {Object} Vue - Vue实例
* @param {Object} vm - 组件实例
*/
const install = (Vue, vm) => {
// 设置默认配置
const defaultConfig = {
loadingText: '努力加载中~',
loadingTime: 800,
showLoading: true,
loadingMask: true
}
setRequestConfig(defaultConfig)
// 将request方法挂载到Vue原型上方便使用
Vue.prototype.$request = {
get: (url, params, options) => {
return import('@/utils/request.js').then(({ get }) => {
return get(url, params, options)
})
},
post: (url, data, options) => {
return import('@/utils/request.js').then(({ post }) => {
return post(url, data, options)
})
},
put: (url, data, options) => {
return import('@/utils/request.js').then(({ put }) => {
return put(url, data, options)
})
},
delete: (url, options) => {
return import('@/utils/request.js').then(({ del }) => {
return del(url, options)
})
},
// 获取当前配置
getConfig: () => getRequestConfig(),
// 设置配置
setConfig: (config) => setRequestConfig(config)
}
console.log('HTTP配置初始化完成')
}
export default {
install
}