api
js
复制代码
import request from '@/tools/request'
export function login(loginMessage) {
return request({
url: '/login',
data: loginMessage,
loading: true
})
}
request
js
复制代码
// request
const urlArr = {
'DEV': 'http://localhost:6060', // 开发
'PRO': 'https://域名:6060', // 生产
}
let BASEURL = urlArr['DEV'] // 调整当前环境
export default item => {
if (item.loading) {
uni.showLoading({
title: "加载中",
mask: true
});
}
return new Promise((resolve, reject) => {
uni.request({
url: BASEURL + item.url,
method: item.method ? item.method : 'post',
data: item.data,
headers: item.headers ? item.headers : { "Content-Type": "application/json" },
timeout: 20000,
success(response) {
resolve(response.data);
},
fail(err) {
uni.showToast({
icon: "none",
title: '服务响应失败'
});
reject(err);
},
complete() {
uni.hideLoading();
}
});
})
};
使用
js
复制代码
import { login,sendCaptcha } from '@/api/login.js'
const res = await login(params)