api.js
717 Bytes
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
import util from '@/libs/util';
class Api {
constructor() {
}
_get(url, data) {
if (!PRODUCTION) {
data = Object.assign({}, data, {
debug: 'XYZ'
});
}
return util.ajax.get(url, data).then(result => result.data);
}
_post(url, data, json = false) {
if (!PRODUCTION) {
url += '?debug=XYZ';
}
const params = json ? data : this._2params(data);
return util.ajax.post(url, params).then(result => {
return result.data;
});
}
_2params(data) {
const params = new URLSearchParams();
for (let i of Object.keys(data)) {
if (data[i]) {
params.append(i, data[i]);
}
}
return params;
}
}
export default Api;