1. // models/Http.js
    2. import axios from 'axios'
    3. axios.defaults.baseURL = 'http://192.168.4.93:7001'
    4. axios.defaults.withCredentials = true;
    5. class Http{
    6. static request({url,method='get',data={},params}){
    7. return axios({
    8. url,
    9. method,
    10. data,
    11. params
    12. })
    13. }
    14. }
    15. export default Http
    1. // models/GoodsHttp.js
    2. import Http from './Http'
    3. class GoodsHttp extends Http{
    4. static getPagination({offset=0,limit=8}){
    5. this.request({
    6. url:'/api/goods',
    7. params:{
    8. offset,
    9. limit
    10. }
    11. })
    12. }
    13. // 获取价格区间0-100
    14. static getPriceRange({min,max}){
    15. this.request({
    16. url:'/api/goods',
    17. params:{
    18. min,
    19. max
    20. }
    21. })
    22. }
    23. // 价格升降序
    24. static getSortPrice(price){
    25. this.request({
    26. url:'/api/sort',
    27. params:{
    28. price
    29. }
    30. })
    31. }
    32. }
    33. export default GoodsHttp