前文我们已经封装了axios的get请求和post请求,接下来实现对api接口的统一管理

首先在src/request/下新建api.js文件,然后引入封装的http.js(get,post)

/**
 * api接口统一管理
 */
import { get, post } from './http'
import Vue from 'vue'

然后定义接口

/**
 * testGet 接口
 * @param {Object} p 请求参数
 */
export const testGet = p => get(Vue.prototype.api + 'TestGet', p)

/**
 * testPost 接口
 * @param {Object} p 请求参数
 */
export const testPost = p => post(Vue.prototype.api + 'TestPost  ', p)

接口定义完成后可在组件中引入api.js并调用接口

//接口调用
import {
    testGet,
    testPost,
} from './../../../../request/api';

 

相关文章:

  • 2021-11-21
  • 2021-06-09
  • 2022-01-06
  • 2022-12-23
  • 2022-01-19
  • 2021-11-10
  • 2021-12-19
  • 2022-12-23
猜你喜欢
  • 2021-07-04
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-01
相关资源
相似解决方案