promise的链式调用 (后面可能会改,指定该函数的状态,因为指定了成功和失败)

1.vuex中的一个异步请求的方法,当请求成功的时候,才执行下一步

getcitydata({ commit }, cityinfo) {
      return new Promise((resolve, reject) => {
        provCityArea(cityinfo).then(res => {       //
          console.log(res, '获取市')
          if (res.code === 0) {
            commit('changecity', res.data)
          }
          resolve(res)
        }).catch(error => {
          reject(error)
        })
      })
    },

2. 调用vuex中的方法,得到promise返回的对象,.then(), 接收两个回调函数,成功和失败,

this.$store.dispatch('getcitydata', { upGbCode: row.gbCode }).then(
        res => {
          console.log(res, '获取市-')
          if (res.code === 0) {
            this.activeName = 'city'       //成功后执行的步骤
          }
        },
        err => {
          console.log(err)
        }
      )
原文地址:https://www.cnblogs.com/shun1015/p/12673029.html