vue.cli项目封装全局axios,封装请求,封装公共的api和调用请求的全过程

参考:https://blog.csdn.net/weixin_43216105/article/details/98877960

我的在uniapp中配置
vue.config.js

module.exports = {
  // 输出目录
  assetsDir: 'static',
  // 基本路径
  // baseUrl: './',
  devServer: {
    proxy: {
      '/seeu': {
        target: 'https://www.seeu.net.cn', //对应自己的接口
        changeOrigin: true,
        ws: true,
        pathRewrite: {
          '^/seeu': '' //忽略api前缀
        }
      },
      '/video': {
        target: 'https://www.bilibili.com/', //对应自己的接口
        changeOrigin: true,
        ws: true,
        pathRewrite: {
          '^/video': '' //忽略api前缀
        }
      },
    }
  }
}

api.js

import http from '../utils/http'
// 
/**
 *  @parms resquest 请求地址 例如:http://197.82.15.15:8088/request/...
 *  @param '/testIp'代表vue-cil中config,index.js中配置的代理
 */
let request = "/music/cloudmusic/"

// get请求
function getListAPI(params){
    return http.get(`${request}`,params)
}
// post请求
function postFormAPI(params){
    return http.post(`${request}`,params)
}
// put 请求
function putSomeAPI(params){
    return http.put(`${request}`,params)
}
// delete 请求
function deleteListAPI(params){
    return http.delete(`${request}`,params)
}

export default{
	getListAPI,
	postFormAPI,
	putSomeAPI,
	deleteListAPI
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值