1. 创建一个 index。js 文件
// api模块化自动加载 const files = require.context('./', true, /\Api.js$/) // eslint-disable-next-line import/no-mutable-exports let apiEntire = {} files.keys().forEach((key) => { const tmp = files(key).default apiEntire = { ...apiEntire, ...tmp } })export default apiEntire 2. 随意放入哪个全局js 文件中 const API = {} for (const i in apiEntire) { // 调用api时候的参数 // 第一位为 data表单提交 第二位为 params参数 第三位为直接追加值 API[i] = function (data = '', params = '', joinUrl = '') { const { url, method, headers } = { ...apiEntire[i] } return $axios({ url: url + joinUrl, method, headers, data, params }) } } app.api = API inject('api', API) 标签:...,vue,const,api,API,data,apiEntire,加载 From: https://www.cnblogs.com/yuerdong/p/17165416.html