3
then()for this.getStationsAsync()
从不运行。 catch()
也没有,所以有可能没有被拒绝。我可以用Promise.promisify(this.getStations)
做错吗?Vue/Bluebird:然后回调不运行
我也试过this.getStationsAsync = Promise.promisify(this.getStations)
里面的created()
挂钩。我没有得到任何错误,但也没有得到任何console.logs()
表明then()
执行。
import Vue from 'vue'
import axios from 'axios'
import Promise from 'bluebird'
methods:{
createStationMarkers (selectedNetworkMarker) {
this.selectedNetwork = selectedNetworkMarker
this.hideNetworkMarkers()
debugger
this.getStationsAsync()
.then(() => {
debugger
console.log('inside then')
this.addStationMarkers()
this.test = true
})
.catch(error => {
console.log(error)
})
}
},
getStations() {
axios
.get('/api/network/' + this.selectedNetwork.id)
.then(res => {
for (let station of res.data.stations) {
this.stations.push(station)
}
return res.data.stations
})
.catch(error => {
console.log(error)
})
}
}
computed: {
getStationsAsync() {
return Promise.promisify(this.getStations)
}
}
并且我认为使用'Bluebird.promisify()'是多余的,因为'axios'也会返回一个承诺......而且它被认为是一种反实践(虽然不确定) –
@ riyaz-ali我同意。 – Bert