# 接口请求
# 相关配置
查看根目录:utils/constant.js文件
- 配置说明如下:
// 全局环境修改: 可选参数dev,test,prod
const ENV = 'dev'
// 后端context-path接口前缀
const BASE_URL = '/api'
// 后端接口多环境配置
const hostConfig = {
dev: "http://localhost:8080",
test: "测试环境api接口",
prod: "生产环境api接口"
}
/**
* 前端页面配置(公众号重定向需要)
*/
const frontIndexConfig = {
dev: "http://www.diboot.com", // 自行替换
test: "",
prod: ""
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
- 当前文件对外提供常量及方法
ENV
:环境变量,发布服务器之前,手动修改ENV
变量为对应环境即可,可选用dev、test、prod;BASE_URL
:对应后端的context-path配置;host()
:后端接口地址前缀;frontIndex()
:前端地址前缀,公众号重定向使用。
TIP
页面中可以直接通过this.$cons
使用上述常量及方法。
# 请求方式
// post请求 "content-type": "application/json;charset=utf-8"
this.$dibootApi.post(url, data)
// get请求
this.$dibootApi.get(url, params)
// put请求
this.$dibootApi.put(url, data)
// delete请求
this.$dibootApi.delete(url, data)
// postForm请求: 'Content-Type': 'application/x-www-form-urlencoded'
this.$dibootApi.postForm(url, data)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
TIP
- 上述仅列出常用几种请求方式,关于请求的限制及更多使用方法请参考
luch-request
文档; - 页面中可以直接通过
this.$dibootApi
调用。