request.js
// 封装请求
const ajax = (url,method,data)=>{
// 显示loading
wx.showLoading({
title: '加载中',
})
return new Promise((resolve,reject)=>{
wx.request({
url: url, //仅为示例,并非真实的接口地址
data:data,
method:method,
header: {
'content-type': 'application/json' // 默认值
},
success (res) {
// console.log(res.data)
resolve(res.data)
// 隐藏loading
wx.hideLoading()
},
fail(err){
reject(err)
}
})
})
}
export default ajax
ajax.js
import ajax from "./request.js"
let base_url = 'http://121.42.230.80/api/'
// 首页推荐套餐接口
export function GetHotHospital(data){
return ajax(base_url+'hothospital','get',data)
}
index.vue
import {GetHotHospital} from "../../utils/http.js"
GetHotHospital(null).then(res => {
console.log(33, res)
this.datalist = res.data
})