forked from mtianyan/vue-mooc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.js
62 lines (56 loc) · 1.32 KB
/
common.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import axios from 'utils/axios.js'
import Axios from 'axios'
import { ERR_OK } from 'api/config.js'
// 获取用户搜索历史
export function getSearchHistory () {
return axios.get(`/api/v1/common/history`)
}
// 生成一条搜索历史
export function createSearchHistory (keyword) {
return axios.post('/api/v1/common/history/', {
params: {
keyword
}
})
}
// 获取热搜词接口
export function getHot () {
return axios.get(`/api/v1/common/hot`)
}
// 获取底部版权footer数据
export function getFooter () {
return axios.get(`/api/v1/common/footer`)
}
// 获取头部数据接口
export function getHeader () {
return axios.get(`/api/v1/common/nav`)
}
// 获取实时搜索数据
export function getSearch (keyword) {
return new Promise((resolve, reject) => {
Axios.get('https://www.imooc.com/search/history', {
params: {
words: keyword
}
}).then(res => {
const { status, data: { result, data } } = res
if (status === 200 && result === 0) {
resolve({
code: ERR_OK,
msg: '获取成功',
data: data
})
} else {
reject({
code: -1,
msg: '获取失败'
})
}
}).catch(error => {
reject({
code: -1,
msg: error.message || '获取失败'
})
})
})
}