itsource

Vue/Bluebird: 콜백이 실행되지 않음

mycopycode 2022. 8. 28. 09:56
반응형

Vue/Bluebird: 콜백이 실행되지 않음

의 then()this.getStationsAsync()실행하지 않습니다.catch()그렇지 않기 때문에 거부되는 것은 없을 것입니다.혹시 제가 잘못하고 있는 건 아닐까요?Promise.promisify(this.getStations)?

나도 해봤어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)
    }
  }

공리 호출 결과를 반환해야 합니다.이것은 약속입니다.

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)
    })
  }
}

Bluebird는 필요 없습니다.전화만 하면 됩니다.getStations부터createStationMarkers.

언급URL : https://stackoverflow.com/questions/46426514/vue-bluebird-then-callback-doesnt-run

반응형