Ajax.js
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var Vue = require('vue');
var host='http://localhost:3003'
host='';
//host='http://192.168.3.206:80/drugcloud_api'
module.exports = {
headers: {},
ajax: function (url, method, data) {
var self = this;
return Vue.http[method](host+url, data, {
beforeSend: function (request) {
//NP.start();
},
headers: self.headers
}).then(function (resp) {
//NP.done();
return resp;
}, function (error) {
//NP.done();
console.error('后端服务器应该是出问题了\n' + error.status + '\n' + error.statusText);
});
},
get: function (url, data) {
return this.ajax(url, 'get', data);
},
get: function (url, data) {
return this.ajax(url, 'get', data);
},
post: function (url, data) {
return this.ajax(url, 'post', data);
},
put: function (url, data) {
return this.ajax(url, 'put', data);
},
patch: function (url, data) {
return this.ajax(url, 'patch', data);
},
delete: function (url, data) {
return this.ajax(url, 'delete', data);
},
jsonp: function (url, data) {
return this.ajax(url, 'jsonp', data);
}
};