fly请求库地址
index.js
const Fly = require("../lib/fly/wx")//引入fly请求库
const fly = new Fly()
fly.config.baseURL = 'http://music.lz7dev.top:9001/'//基础路径
fly.interceptors.response.use((response) => {
//只将请求结果的data字段返回
return response.data
}
)
module.exports = fly
api.js
const fly = require('./index')
export default {
getbanner() {
//轮播图
return fly.get('/banner')
},
gettopartists(type,area,initial,offset,limit){
//热门歌手
return fly.get(`/artist/list?type=${
type}&area=${
area}&initial=${
initial}&offset=${
offset}&limit=${
limit}`)
},
}
js
//import api from '../../http/api'
const {
default: api
} = require("../../http/api")
//轮播图
getbanner() {
api.getbanner().then(res => {
this.setData({
banners: res.banners
})
console.log(res, "轮播图数据")
}).catch(err => {
console.log(err)
})
},
//热门歌手
gettopartists() {
let a = this.data.typeList[this.data.singer].type
let b = this.data.typeList[this.data.singer].area
let c = this.data.initials[this.data.hot].id
let d = this.data.offset
let e = this.data.limit
api.gettopartists(a, b, c, d, e).then(res => {
this.setData({
artists: res.artists
})
console.log(res.artists, '歌手清单')
}).catch(err => {
console.log(err)
})
},