Skip to content

TGapi

API use case

JS
api前缀:/api
token:'Bearer '+'token部分xxx'

🍓 GET

js
axios({
  method: 'get',
  url: 'http://localhost:8888/api/user',
  headers: {
    'Authorization': 'Bearer '+'token部分',
    'Content-Type': 'application/json;charset=utf-8',
    'Custom-Header': 'custom-value'
  },
  params: {
      name: '名字',
      age: '年龄',
      pageNum: 1, //请求页数
      pageSize: 10,//请求条数
  },
})
.then(res => {
  console.log(res.data)
  if (res.status == 200) {
    console.log(res, 'res');
  }
})
.catch(error => {
  console.error(error)
})

🍓 POST

js
axios({
  method: 'post',
  url: 'http://localhost:8888/api/user',
  headers: {
    'Authorization': 'Bearer '+'token部分',
    'Content-Type': 'application/json;charset=utf-8',
    'Custom-Header': 'custom-value'
  },
  data: {
      name: '名字', // 必填项
      age: '年龄', // 必填项
      sex:1, // 下拉选择-必填项
  },
})
.then(res => {
  console.log(res.data)
  if (res.status == 200) {
    console.log(res, 'res');
  }
})
.catch(error => {
  console.error(error)
})

🍓 PUT

js
axios({
  method: 'put',
  url: 'http://localhost:8888/api/user',
  headers: {
    'Authorization': 'Bearer '+'token部分',
    'Content-Type': 'application/json;charset=utf-8',
    'Custom-Header': 'custom-value'
  },
  data: {
      name: '名字', // 必填项
      age: '年龄', // 必填项
      sex:1, // 下拉选择-必填项
  },
})
.then(res => {
  console.log(res.data)
  if (res.status == 200) {
    console.log(res, 'res');
  }
})
.catch(error => {
  console.error(error)
})

🍓 DELETE

js
axios({
  method: 'delete',
  url: 'http://localhost:8888/api/user',
  headers: {
    'Authorization': 'Bearer '+'token部分',
    'Content-Type': 'application/json;charset=utf-8',
    'Custom-Header': 'custom-value'
  },
  data: {
      id: 0, // 必填删除id
  },
})
.then(res => {
  console.log(res.data)
  if (res.status == 200) {
    console.log(res, 'res');
  }
})
.catch(error => {
  console.error(error)
})