Skip to content

Commit c3e477b

Browse files
author
Riley Ren
committed
extract api url
1 parent 9aaebc4 commit c3e477b

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

src/api/request.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios from 'axios';
22
import qs from 'qs';
3-
import { API_URL } from 'config';
3+
import { API_BASE_URL } from 'config';
44

55
axios.interceptors.request.use((config) => {
66
config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
@@ -15,7 +15,7 @@ axios.interceptors.request.use((config) => {
1515

1616
function baseRequest(url, params, method = 'get') {
1717
return new Promise((resolve, reject) => {
18-
axios[method](`${API_URL}${url}`, params).then((response) => {
18+
axios[method](`${API_BASE_URL}${url}`, params).then((response) => {
1919
const json = response.data;
2020
if (parseInt(json.code, 10) === 0) {
2121
resolve(json.data);

src/api/sign.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { get, post } from './request';
2+
import * as apis from '@/conf/apis';
23

34
export default {
4-
signIn: (user, password) => post('signin.php', {
5+
signIn: (user, password) => post(apis.SIGN_IN, {
56
user,
67
password
78
}),
8-
signOut: () => get('signout.php'),
9+
signOut: () => get(apis.SIGN_OUT),
910
};

src/api/todo.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import { get, post } from './request';
2+
import * as apis from '@/conf/apis';
23

34
export default {
4-
fetch: () => get('fetch.php'),
5-
save: (todos) => post('save.php', {
5+
fetch: () => get(apis.FETCH_TODO),
6+
save: (todos) => post(apis.SAVE_TODO, {
67
data: JSON.stringify(todos),
78
action: 'save',
89
}),
9-
add: (todo) => post('save.php', {
10+
add: (todo) => post(apis.SAVE_TODO, {
1011
data: JSON.stringify(todo),
1112
action: 'add',
1213
}),
13-
remove: (todo) => post('save.php', {
14+
remove: (todo) => post(apis.SAVE_TODO, {
1415
data: todo.id,
1516
action: 'remove',
1617
}),
17-
modify: (todo) => post('save.php', {
18+
modify: (todo) => post(apis.SAVE_TODO, {
1819
data: JSON.stringify(todo),
1920
action: 'modify',
2021
}),

src/conf/apis.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export const FETCH_TODO = 'fetch.php';
22
export const SAVE_TODO = 'save.php';
3+
4+
35
export const SIGN_IN = 'signin.php';
46
export const SIGN_OUT = 'signout.php';

src/conf/config-dev.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
// export const API_URL = 'http://172.16.21.236/vue-test-api/';
2-
export const API_URL = 'http://127.0.0.1/vue-test-api/';
1+
export const API_BASE_URL = 'http://127.0.0.1/vue-test-api/';

src/conf/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const API_URL = 'http://127.0.0.1/vue-test-api/';
1+
export const API_BASE_URL = 'http://127.0.0.1/vue-test-api/';

0 commit comments

Comments
 (0)