我如何从vue 2中的promise中调用该方法?

时间:2018-01-29 13:28:41

标签: javascript promise vuejs2 vue-component

 var cityPromise = new Promise(function (resolve, reject) {
      this.getAllCities();
      this.cities = this.cities.filter(data => {
        if (data.country_id === this.filCountry) {
          return data;
        }
      });
      resolve();

    });

我需要等到响应从ajax调用到达,然后对接收到的数据执行操作吗?

1 个答案:

答案 0 :(得分:0)

一旦承诺返回,您将使用then

cityPromise.then(data => {
    // do something with data
})