2017-09-26 13 views
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) 
    } 
    } 

答えて

3

あなたはリターン約束ですaxios呼び出し、結果を必要とします。

getStations() { 
    return 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) 
    }) 
    } 
} 

ブルーバードが不必要です。 createStationMarkersからgetStationsに電話するだけです。

+0

また、私はBluebird.promisify()を使用していることが冗長でaxiosも約束を返すと考えています...また、反実践と考えられています(確かではありません) –

+0

@ riyaz-ali – Bert

関連する問題