第一种:get params
export async function togetFreight(params) {
const res = await request("/tc_api/api/getFreight", {
method: "get",
params: params,
});
return res;
},
loadGetFreight(_name) {
return togetFreight({ name: _name }).then((res) => {
if (res.code == 0 && res.data) {
this.shipList = res.data;
}
});
},
第二种:get url后面带参数 可以跟第三种做比较 有相似也有不同 第二种的/后面带id,
第三种是?id=' + _data.id,
export async function getProductById(_id) {
const res = await request("/tc_api/api/product/" + _id, {
method: "get",
});
return res;
},
loadPage() {
return getProductById(this.id)
.then((res) => {
if (res && res.code == 0 && res.data) {
this.m_id = res.data.id;
this.productList = res.data;
}
})
.finally(() => {
this.$loading.hide();
});
},
第三种:默认get 没有写method的话 头部带token url带参 ts
export function getNoticeinfo(_data: any, _token: string) {
return request({
url: "/diag_api" + '/api/notice/info?id=' + _data.id,
headers: {
Authorization: 'Bearer ' + _token
}
});
},
getNoticeinfo({id:query.id},query.token).then((res: any) => {
detailInfo.value = res;
}).catch((err) => {
console.log(err);
}).finally(()=> {
isInitial.value = true;
});
第四种:get 可以跟第一种做下比较 应该是一样的
export function getFaqDetail(_data: any, _token: string) {
return request({
url: "/diag_api" + '/api/get/faqDetail',
headers: {
Authorization: 'Bearer ' + _token
},
params: {
id: _data.id,
from: _data.from
}
});
}
第五 种:get 携带了两个参
export function mallSignList(_token: string, offset: number) {
return request({
url: "/diag_api" + '/api/user/signInfo',
params: { offset },
headers: {
Authorization: 'Bearer ' + _token
}
});
},
mallSignList(token as string, offset).then((res: any) => {}
第六种:get 带参
export function docsData(app_id: any) {
return request({
url: "/online_api/api/product/instructions",
params: { app_id }
})
},
docsData(route.params.sn).then((res: any) => {}
第七种: get 不携带参数
export async function getNotice() {
const res = await request("/tc_api/api/getNotice", {
method: "get",
});
return res;
},
loadGetNotice() {
return getNotice().then((res) => {
if (res.code == 0 && res.data) {
this.noticeContent = res.data.content;
}
});
},