Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 188cf15

Browse files
committed
初步封装请求木块
1 parent 5001ae2 commit 188cf15

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

src/api/commont.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { get } from '../utils/request'
2+
3+
export function getTotic(params) {
4+
/**
5+
* @description 获取主题
6+
* @param {string} tab 顶部tab,如果全部,可不传或all,其他使用 node name
7+
* @param {number} p 第几页,不传代表第1页
8+
*/
9+
return get('/topics', params)
10+
}
11+
export function getToticDetail(params) {
12+
/**
13+
* @description 获取主题详情
14+
* @param {number} tid 主题id
15+
*/
16+
return get('/topic/detail', params)
17+
}
18+

src/article/Index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default Vue.extend({
2121
name: 'Article',
2222
data() {
2323
return {
24-
article:{
24+
article: {
2525
author: {
2626
avatar: 'http://img1.3lian.com/gif/more/11/2012/03/d037a77443c0a72a1432d815cd3b5724.jpg',
2727
nickname: '昵称'

src/utils/request.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
const baseUrl = 'https://studygolang.com/app'
3+
function request({ url, data, method }) {
4+
const header = {
5+
token: wx.getStorageSync('token') || '',
6+
}
7+
return new Promise((resove, reject) => {
8+
wx.request({
9+
url: baseUrl + url,
10+
method,
11+
data: { ...data, from: 4 },
12+
header,
13+
success: (res) => {
14+
resove(res.data)
15+
},
16+
fail: (res) => {
17+
reject(res)
18+
}
19+
})
20+
})
21+
}
22+
23+
function get(url, data) {
24+
return request({ url, method: 'get', data })
25+
}
26+
function post(url, data) {
27+
return request({ url, method: 'post', data })
28+
}
29+
30+
export {
31+
request,
32+
get,
33+
post
34+
}

0 commit comments

Comments
 (0)