扩展 axios 能力的工具集 axios-tools
汇集 axios 的能力扩展,并配备最佳实践
在项目中使用,具体示例参见 axios-tools/usage
src/utils/request.js
src/service/index.js
// 业务封装
import axios from 'axios'
import createTaroAdapter from '@deepjs/axios-taro-adapter'
// import createUniappAdapter from '@deepjs/axios-uniapp-adapter'
import Taro from '@tarojs/taro'
axios.defaults.adapter = createTaroAdapter(Taro.request)
// axios.defaults.adapter = createUniappAdapter(uni.request)
const instance = axios.create({
baseURL: 'https://m.xxx.com',
})
instance.get('https://m.xxx.com/common/initconfig')
.then(resp => {
console.log('GET请求成功:', resp)
})
export const request = instance;
引用
import { request } from '@/utils/request'
export function getConfig(data = {}) {
return request('/common/initconfig', {
method: 'GET',
params: data,
})
}
其他同类项目