1 import axios from 'axios'
2
3 // let curWwwPath = window.document.location.href
4 // let pathname = window.document.location.pathname
5 // let pos = curWwwPath.indexOf(pathname)
6 // let localhostPath = curWwwPath.substring(0, pos)
7 // let root = localhostPath + pathname
8
9 const root = 'http://localhost:8097/'
10
11 function _sendRequest (url, method, data, callback, responsetype) {
12 axios({
13 method: method,
14 url: url,
15 data: method === 'POST' || method === 'post' || method === 'PUT' || method === 'put' ? data : null,
16 params: method === 'GET' || method === 'get' || method === 'DELETE' || method === 'delete' ? data : null,
17 baseURL: root19 }).then(function (response) {
20 console.log(response)
21 callback(response.data)
22 }).catch(function (error) {
23 if (error.response) {
24 console.log('Error' + error.response.data)
25 console.log('Error' + error.response.status)
26 console.log(error.response.headers)
27 } else {
28 console.log('Error', error.message)
29 }
30 console.log(error.config)
31 })
32 }
33
34 export default {
35 sendRequest: function (url, method, data, callback, responseType) {
36 _sendRequest(url, method, data, callback, responseType)
37 }
38 }