3
this.getStationsAsync()
のthen()は実行されません。 catch()
もどちらでもないので、何も拒否されない可能性があります。 Promise.promisify(this.getStations)
で何か問題が起こっていますか?Vue/Bluebird:コールバックは実行されません
また、created()
フックの内側にthis.getStationsAsync = Promise.promisify(this.getStations)
を試しました。私はどんなエラーも出ていませんが、then()
が実行されたことを示すconsole.logs()
も表示されません。
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