params 是即将与请求一起发送的 URL 参数

data 是作为请求主体被发送的数据 只适用于这些请求方法 'PUT', 'POST', 和 'PATCH'

使用封装的request

import request from '../utils/request'
const group_name = 'user'
export default {
  userList(page) {
    return request({
      url: `/${group_name}/page`,
      method: 'post',
      data: page
    })
  },
  update(user) {
    return request({
      url: `/${group_name}/update`,
      method: 'put',
      data: user
    })
  },
  deleteById(id) {
    return request({
      url: `/${group_name}/delete//${id}`,
      method: 'delete'
    })
  },
  save(user) {
    return request({
      url: `/${group_name}/save`,
      method: 'post',
      data: user
    })
  },
  getById(id) {
    return request({
      url: `/${group_name}/get//${id}`,
      method: 'get'
    })
  },
}

使用此方法封装,可在页面通过解构赋值来进行调用

export function getRoles() {
    return request({
        url: '/vue-element-admin/roles',
        method: 'get'
    })
}
export function addRole(data) {
    return request({
        url: '/vue-element-admin/role',
        method: 'post',
        data
    })
}
export function updateRole(id, data) {
    return request({
        url: `/vue-element-admin/role/${id}`,
        method: 'put',
        data
    })
}
export function deleteRole(id) {
    return request({
        url: `/vue-element-admin/role/${id}`,
        method: 'delete'
    })
}