完成接口的封装

main
roger_home_pc 1 year ago
parent 31726188ef
commit 4aa3240003
  1. 25
      src/api/basic.js
  2. 43
      src/api/goods.js
  3. 44
      src/api/order.js
  4. 41
      src/api/users.js
  5. 1
      src/utils/requests.js

@ -0,0 +1,25 @@
import request from '@/utils/request'
// 封装请求的方式
export function addAddress(data) {
return request({
url: '/address/',
method: 'post',
data
})
}
export function getAddress(data) {
return request({
url: '/address/',
method: 'get',
data
})
}
export function updateAddress(id, data) {
return request({
url: '/address/' + id + '/',
method: 'patch',
data
})
}

@ -0,0 +1,43 @@
import request from '@/utils/requests'
// get方式请求商品分类
export function getGoodsCategory () {
return request({
url: '/goodscategory()', method: 'get',
})
}
// 获取某个商品分类
export function getGoodsCategoryById (id) {
return request({
url: '/goodscategory/' + id + '/', method: 'get',
})
}
// 获取分类下的商品
export function getCategoryGoods () {
return request({
url: '/indexgoods/', method: 'get',
})
}
// 通过参数方式获取商品
export function getGoods (data) {
return request({
url: '/goods/', method: 'get', params: data
})
}
// 通过id获取某个商品
export function getGoodsByID (id) {
return request({
url: '/goods/' + id + '/', method: 'get',
})
}
export function getSlide () {
return request({
url: '/slide/', method: 'get',
})
}

@ -0,0 +1,44 @@
import request from '@/utils/request'
// 封装请求的方式
export function addCart(data) {
return request({
url: '/cart/',
method: 'post',
data
})
}
export function getCart(data) {
return request({
url: '/cart/',
method: 'get',
data
})
}
export function updateCart(id,data) {
return request({
url: '/cart/'+id+'/',
method: 'patch',
data
})
}
export function addOrder(data) {
return request({
url: '/order/',
method: 'post',
data
})
}
export function getOrder(data) {
return request({
url: '/order/',
method: 'get',
data
})
}

@ -0,0 +1,41 @@
import request from '@/utils/request'
// 封装请求的方式
export function login(data) {
return request({
url: '/login/',
method: 'post',
data
})
}
export function reg(data) {
return request({
url: '/users/',
method: 'post',
data
})
}
export function getUsersByID() {
return request({
url: '/users/1/',
method: 'get',
})
}
export function updateUsers(data) {
return request({
url: '/users/1/',
method: 'patch',
data
})
}
export function updatePwd(data) {
return request({
url: '/users/1/',
method: 'patch',
data
})
}

@ -1,4 +1,5 @@
import axios from 'axios'
import {url} from 'nightwatch/examples/pages/home'
// 官方文档 https://www.axios-http.cn/

Loading…
Cancel
Save