### http封装(类)
var base_url = "http://t.yushu.im/v2/movie/";
class HTTP{
request({url,data={},method="GET",success}){
wx.request({
url:base_url+url,
data,
method,
header: {
'Content-Type': 'application/json'
},
success: (res)=>{
success(res)
}
})
}
}
类导出:
export {HTTP}
### 类继承
import {HTTP} from "./HTTP";
class MovieModel extends HTTP{
getTop250(callback){
this.request({ //this使用继承方法
url:"top250",
callback:res=>{
callback(res);
}
})
};
getOnReachBottom(url,callback){
this.request({
url,
callback:res=>{
callback(res)
}
})
};
getDetail(url,callback){
this.request({
url,
callback:res=>{
callback(res)
}
})
}
}
继承类导出
export {MovieModel};
创建对象
import {MovieModel} from "../../models/MovieModel";//需要使用相对地址
const movieModel = new MovieModel();