http.js
const service = axios.create({ baseUrl: '//apixh-beta.17win.com', // window.xhHost['solar-api'], // 'apixh-beta.17win.com', timeout: 5000 }) service.interceptors.request.use( config => { //... }, err => { //... } )// ...export default service
api.js
import Http from '@/http'export default { getData (params) { console.log('get my cert...') return Http({url:'/api/XXX', method: 'get', params}) }}
home.js
import Service from '@/api.js' Service.getMyCert({}).then(response => {}) // 这里request URL: http://localhost:3000/api/xxx
axios.create设置了baseUrl,但是实际请求的baseUrl还是localhost:3000/api/xxx
Helenr
相关分类