53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
|
|
// 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
|
|||
|
|
}
|