//request.js var host = 'https://www.xxx.com';//请求域名 module.exports = function (type, params, method) { return new Promise((resolve, reject) => { wx.request({ url: `${host}/${type}`, data: params, method: method || 'GET', header: { 'content-type': 'json' }, success: function(res){ resolve(res.data); }, fail: reject, }) }) } //api.js所有api接口存放的文件 var request = require('./request.js');//引入request.js文件(注意自己的引入路径) var api = { citys: data => { return request('请求接口名称',data,'get') } } module.exports = api //导出所有请求接口 //index.js const api = require('../request/api.js'); var data = { params1:'参数1', params2:'参数2', }//请求参数 api.citys(data).then(res=> { console.log(res); })