//首先创建一个存放ajax的文件夹,里面创建ajax.js
//配置:
// 这个文件封装数据请求
// 服务器基础地址
const baseUrl = "https://autumnfish.cn/"
//比如:
// const baseUrl = "https://localhost:3000/"
// 通用的请求函数
function requeat(url, data={}){
wx.showLoading()
return new Promise(resolve=>{
wx.request({
url, data,
success(res){
resolve(res.data)
wx.hideLoading()
}
})
})
}
//设置需要请求的变量
const 变量名 = data => requeat(baseUrl+'后缀地址', data)
// ES6按需导出
export {
变量名
}
// node按需导出
// module.exports = {
// loginByPhone
// }
//在需要调用的时候
//引入封装好的ajax文件
import { 变量 } from "../../文件夹/ajax.js"
//再获取信息
变量({
条件(没有就为空)
}).then(res=>{
console.log("数据",res);
})