1.新建一个utils/HTTP.js

  1. var baseUrl="https://music.aityp.com/"
  2. class HTTP{
  3. static request({url,data,method="GET"}){
  4. return new Promise((resolve,reject)=>{
  5. wx.request({
  6. url:baseUrl+url,
  7. data,
  8. header: {'content-type':'application/json'},
  9. method,
  10. dataType: 'json',
  11. responseType: 'text',
  12. success: (res) => {
  13. resolve(res)
  14. },
  15. fail: (err) => {
  16. reject(err)
  17. },
  18. });
  19. })
  20. }
  21. }
  22. module.exports=HTTP

2.utils/DetailModel.js

  1. const HTTP=require('./HTTP')
  2. class DetailModel extends HTTP{
  3. static getDetail(id){
  4. return this.request({
  5. url:"playlists/detail?id="+id,
  6. })
  7. }
  8. }
  9. module.exports=DetailModel

3.页面使用

  1. const DetailModel=require('../../utils/DetailModel')
  2. async onLoad(options){
  3. var {id}=options;
  4. var res==awawit DetailModel.getDetail(id);
  5. ....
  6. }