Skip to content
生如风生如风
主页
github icon
  • get:
    • post:

      vue-admin-template学习(二)

      author icon生如风calendar icon2021年3月20日category icon
      • Vue
      tag icon
      • Vue
      • vue-admin-template
      timer icon小于 1 分钟

      此页内容
      • get:
      • post:

      # vue-admin-template get和post请求及带参方式

      # get:

      (1)在url后面拼接单独的值,例如:localhost:80/student/1 查找id为1的学生信息

      student为固定的url中的字段,1为id的值,会变化,那么在vue-admin-template的api中可以写如下方式:

      export function getOne(id) {
        return request({
          url: `/student/${id}`,
          method: 'get'
        })
      }
      
      1
      2
      3
      4
      5
      6

      在request的url中使用 `` 即可将id作为值拼入。

      (2)请求使用key=value方式访问,例如:localhost:80/student?id=1 查找id为1的学生信息

      export function getOne(id) {
        return request({
          url: '/student',
          method: 'get',
          params: {
            id
          }
        })
      }
      
      1
      2
      3
      4
      5
      6
      7
      8
      9

      传递多个参数,例如:localhost:80/student?id=1&sex=man

      export function getOne(id) {
        return request({
          url: '/student',
          method: 'get',
          params: {
            id,  // 或者改为id: id,
            sex: 'man' // 因为这里没有sex的动态值,固测试使用定值man,可通过方法传递
          }
        })
      }
      
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10

      # post:

      提交学生信息:

      export function commit(data) {
        return request({
          url: '/student/add',
          method: 'post',
          data
        })
      }
      
      1
      2
      3
      4
      5
      6
      7
      默认页脚
      Copyright © 2026 生如风