1.新建一个utils/HTTP.js
var baseUrl="https://music.aityp.com/"
class HTTP{
static request({url,data,method="GET"}){
return new Promise((resolve,reject)=>{
wx.request({
url:baseUrl+url,
data,
header: {'content-type':'application/json'},
method,
dataType: 'json',
responseType: 'text',
success: (res) => {
resolve(res)
},
fail: (err) => {
reject(err)
},
});
})
}
}
module.exports=HTTP
2.utils/DetailModel.js
const HTTP=require('./HTTP')
class DetailModel extends HTTP{
static getDetail(id){
return this.request({
url:"playlists/detail?id="+id,
})
}
}
module.exports=DetailModel
3.页面使用
const DetailModel=require('../../utils/DetailModel')
async onLoad(options){
var {id}=options;
var res==awawit DetailModel.getDetail(id);
....
}