import config from "./config.js" class Http { constructor() { } get (params) { uni.showLoading({ title: '加载中' }); return new Promise(function(resolve, reject) { uni.request({ url: `${config.BaseUrl}${params.url}`, //仅为示例,并非真实接口地址。 data: params.data || {}, method: 'GET', header: params.header || {}, success: (res) => { uni.hideLoading(); if(res.data.status == 200) { resolve(res.data.data) } else { uni.showToast({ title: res.data.data, duration: 2000 }); } }, fail: (error) => { uni.hideLoading(); uni.showToast({ title: error.message, duration: 2000 }); } }); }) } post (params) { uni.showLoading({ title: '加载中' }); return new Promise(function(resolve, reject) { uni.request({ url: `${config.BaseUrl}${params.url}`, //仅为示例,并非真实接口地址。 data: params.data || {}, method: 'POST', header: params.header || {}, success: (res) => { uni.hideLoading(); if(res.data.status == 200) { resolve(res.data.data) } else { resolve(res.data.data) uni.showToast({ title: res.data.data, duration: 2000 }); } }, fail: (error) => { uni.hideLoading(); uni.showToast({ title: error.message, duration: 2000 }); } }); }) } } export default new Http()