Commit e2eaa8a22bf7709ba95bc19172c2c85dc8e4c944
1 parent
697c1032cd
Exists in
master
请求地址提取
Showing
4 changed files
with
110 additions
and
20 deletions
Show diff stats
src/store/modules/myOrder.js
File was created | 1 | const state = { | |
2 | orderList: [], | ||
3 | }; | ||
4 | |||
5 | const mutations = { | ||
6 | getOrder: (state, data) => { | ||
7 | state.orderList = data; | ||
8 | }, | ||
9 | }; | ||
10 | |||
11 | const actions = { | ||
12 | fetch({ commit }, param) { | ||
13 | uni | ||
14 | .request({ | ||
15 | url: "", | ||
16 | method: "post", | ||
17 | data: {}, | ||
18 | header: { | ||
19 | "Content-Type": "application/x-www-form-urlencoded", | ||
20 | }, | ||
21 | timeout: 3000, | ||
22 | withCredentials: false, | ||
23 | success: (res) => { | ||
24 | commit('getOrder', res.data.data) | ||
25 | }, | ||
26 | fail: (res) => { | ||
27 | console.log("fail status === > ", res); | ||
28 | }, | ||
29 | complete: (res) => { | ||
30 | console.log("complete status === > ", res); | ||
31 | } | ||
32 | }) | ||
33 | } | ||
34 | } | ||
35 | |||
36 | export default { | ||
37 | namespaced: true, | ||
38 | state, | ||
39 | mutations, | ||
40 | actions, | ||
41 | } |
src/store/modules/test.js
1 | import urlAlias from '../url'; | ||
2 | import request from '../request'; | ||
3 | |||
4 | const { | ||
5 | shopList | ||
6 | } = urlAlias; | ||
7 | |||
1 | const state = { | 8 | const state = { |
2 | list: [], | 9 | list: [], |
3 | }; | 10 | }; |
4 | 11 | ||
5 | const mutations = { | 12 | const mutations = { |
6 | INIT: (state, list) => { | 13 | INIT: (state, list) => { |
7 | state.list = list; | 14 | state.list = list; |
8 | }, | 15 | }, |
9 | }; | 16 | }; |
10 | 17 | ||
11 | const actions = { | 18 | const actions = { |
12 | fetch({ commit }, param) { | 19 | fetch({ commit }, param) { |
13 | uni | 20 | request({ |
14 | .request({ | 21 | url: shopList, |
15 | url: "https://api.glass.xiuyetang.com/app/prod/list", | 22 | success: (res) => { |
16 | method: "post", | 23 | commit('INIT', res.data.data) |
17 | data: {}, | 24 | }, |
18 | header: { | 25 | fail: (res) => { |
19 | "Content-Type": "application/x-www-form-urlencoded", | 26 | console.log("fail status === > ", res); |
20 | }, | 27 | }, |
21 | timeout: 3000, | 28 | complete: (res) => { |
22 | withCredentials: false, | 29 | console.log("complete status === > ", res); |
23 | success: (res) => { | 30 | }, |
24 | commit('INIT', res.data.data) | 31 | }) |
25 | }, | 32 | // uni |
26 | fail: (res) => { | 33 | // .request({ |
27 | console.log("fail status === > ", res); | 34 | // url: "https://api.glass.xiuyetang.com/app/prod/list", |
28 | }, | 35 | // method: "post", |
29 | complete: (res) => { | 36 | // data: {}, |
30 | console.log("complete status === > ", res); | 37 | // header: { |
31 | }, | 38 | // "Content-Type": "application/x-www-form-urlencoded", |
32 | }); | 39 | // }, |
40 | // timeout: 3000, | ||
41 | // withCredentials: false, | ||
42 | // success: (res) => { | ||
43 | // commit('INIT', res.data.data) | ||
44 | // }, | ||
45 | // fail: (res) => { | ||
46 | // console.log("fail status === > ", res); | ||
47 | // }, | ||
48 | // complete: (res) => { | ||
49 | // console.log("complete status === > ", res); | ||
50 | // }, | ||
51 | // }); | ||
33 | }, | 52 | }, |
34 | }; | 53 | }; |
35 | 54 | ||
36 | export default { | 55 | export default { |
37 | namespaced: true, | 56 | namespaced: true, |
38 | state, | 57 | state, |
39 | mutations, | 58 | mutations, |
40 | actions, | 59 | actions, |
41 | }; | 60 | }; |
42 | 61 |
src/store/request.js
File was created | 1 | const DOMAIN = 'https://api.glass.xiuyetang.com/'; | |
2 | |||
3 | export default async function request({ | ||
4 | url, | ||
5 | success, | ||
6 | fail, | ||
7 | complete, | ||
8 | }) { | ||
9 | console.log("DOMAIN", DOMAIN, url); | ||
10 | uni | ||
11 | .request({ | ||
12 | url: DOMAIN + url, | ||
13 | method: "post", | ||
14 | data: {}, | ||
15 | header: { | ||
16 | "Content-Type": "application/x-www-form-urlencoded", | ||
17 | }, | ||
18 | timeout: 3000, | ||
19 | withCredentials: false, | ||
20 | success, | ||
21 | fail, | ||
22 | complete, | ||
23 | }) | ||
24 | } |
src/store/url.js
File was created | 1 | const urlAlias = { | |
2 | // 获取首页商品列表 | ||
3 | shopList: 'app/prod/list', | ||
4 | } | ||
5 | |||
6 | export default urlAlias; | ||
7 |