我正在尝试抽象出使用promises的数据加载函数,但现在我不确定如何从另一个模块调用该函数...... :(
dataservice模块
export default class DataService {
loadStudents() {
return window.fetch("data.json")
.then(res => res.json())
.then(res => {
// I want to return the result not a promise?
return res
})
}
}
主应用模块
import DataService from "../classes/dataservice"
const ds = new DataService()
ds.loadStudents().then(res => {
// here I just want the data, not a promise...
console.log(res)
})