[已解决]promise修改getClassic下一步问题
来源:11-8 Promise的正确用法

力哥
2018-10-23
classic.js
getClassic(nextOrPrev, index){
const classic = this._getHasClassic(nextOrPrev,index)
if (!classic) {
return this.request({
url: '/classic/' + index + '/' + nextOrPrev
})
}
else{
return classic
}
}
_getHasClassic(nextOrPrev,index){
const key = nextOrPrev == 'next' ? this._getKey(index + 1) : this._getKey(index - 1)
const classic = wx.getStorageSync(key)
return classic
}
index.js
_upClassic(nextOrPrve) {
const getClassic = classicModel.getClassic(nextOrPrve, this.data.classic.index)
const hasClassic = classicModel._getHasClassic(nextOrPrve, this.data.classic.index)
if (hasClassic){
//console.log(getClassic)
this._setData(getClassic)
}
else{
getClassic.then(res=>{
//console.log(res)
wx.setStorageSync(classicModel._getKey(res.index), res)
this._getClassicLikeStatus(res.id, res.type)
this._setData(res)
})
}
},
_setData(data){
this.setData({
classic: data,
last: classicModel._isLast(data.index),
frist: classicModel._isFrist(data.index)
})
},
已解决,正确的我贴下,仅供参考
写回答
1回答
-
phoock
2018-10-23
因为有缓存以后返回的classic不是Promise对象了.所有没有then方法
else{
return classic
} 改成else{
return new Promise(resolve=>resolve(classic))
}应该就可以了
10
相似问题