get
1、直接查询
// 封装的接口
import request from "@/utils/request";
export function listHwatchinfo(query) {
return request({
url: "/system/hwatchinfo/list",
method: "get",
params: query,
});
}
// 请求
listHwatchinfo().then((response) => {
});
2、根据id查询
// 根据id查询
export function getHwatchtype(id) {
return request({
url: "/system/hwatchtype/" + id,
method: "get",
});
}
export function getHwatchtype(id) {
return request({
url: "/system/hwatchtype/",
method: "get",
params: { id },
});
}
// 请求
getHwatchtype(id).then((response) => {
});
// 当需传多个参数的写法
export function getHistoryInfo(personId, counter) {
return request({
method: "get",
url: "/system/baseinfo/getHistoryInfo",
params: { personId, counter },
});
}
export function getHistoryInfo(personId, counter) {
return request({
method: "get",
url: `/system/baseinfo/getHistoryInfo?personId=${personId}&couter=${counter}`,
});
}
// 请求:需按照接口定义的传参顺序传参
getHistoryInfo(this.userId, this.historyForm.counter).then((res) => {})
// 若直接使用params
export function getHistoryInfo(params) {
return request({
method: "get",
url: "/system/baseinfo/getHistoryInfo",
params,
});
}
// 请求
getHistoryInfo({userId:this.userId, counter:this.historyForm.counter}).then((res) => {})
其余请求
1、传参要求为Content-Type:application/json
// 根据类型查询
export function addHwatchtype(data) {
return request({
url: "/system/hwatchtype",
method: "post",
data,
});
}
// 请求json方式传参
addHwatchtype(this.form).then((response) => {
});
总结
get请求传参都是params,其余请求都为data
传参要求为JSON时,直接将整个对象传入即可
无传参要求时,用{key:value,key:value}的形式传入;若接口定义了具体传参顺序即直接传对应的value即可
传参要求为form-data时,需要以下处理
// 由于传参格式为fromdata因此需要以下处理
// 数据为对象
let form = new FormData();
form.append("deviceid", deviceid);
form.append("command", command);
submitcommand(form).then();