盘点前端接口传参的get方式

第一种: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;

        }

      });

    },

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值