const apiHost = 'http://47.108.174.44:3000';
/**
* 统一调用接口
*/
export default function request(url,data,method) {
return new Promise((resolve, reject) => {
wx.showLoading({ title: '加载中...', duration: 6000})
wx.request({
url: apiHost + url,
data: data || {},
header: {
'Content-Type': 'application/json;charset=UTF-8',
},
method: method || 'GET',
dataType: 'json',
responseType: 'text',
success: res => {
wx.hideLoading()
let statusCode = res.statusCode
if(statusCode == 200){
resolve(res.data)
}else{
reject(res)
}
},
fail: res => {
wx.hideLoading()
wx.showToast({
title: '网络异常,请检查网络状态',
icon: 'none',
duration: 3000
})
reject(res)
},
})
})
}
/**
* get方法
*/
// exports.getStudentInfo = function (openid) {
// let url = '/student/getByOpenId?open_id=' + openid
// return request( url )
// }
/**
* post方法
*/
// exports.saveStudentInfo = function (data) {
// let url = '/student/save'
// return request( url , data , "POST" )
// }
import request from "../utils/request"
/**
* get方法
*/
export function getBanner(openid) {
let url = '/banner?type=' + openid
return request( url );
}
getBanner(2).then(function(res){
console.log("success:",res);
}).catch(function(errerr){console.log(err)});
export default{
host:'https://www.shijiayi.top:4000'
}
//导入配置文件
import config from "./config"
url: config.host+url, //仅为示例,并非真实的接口地址
最后修改于 2022-05-05 08:26:46
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付

