Promise then连用

2020-09-17  本文已影响0人  夜色001

1、Promise then连用时,上一个then的返回值是下一个then的输入

通常用return,否则下一个then的参数为空。
Promise连用的写法,可以避免调用接口多层嵌套,显得更加美观

2、this的指代

this通常谁调用指代谁,为了避免不必要的混乱,可以全局设置this,以指向当前控件

handleDelete(row) {
      const _this = this
      this.$confirm('是否确认删除名称为"' + row.name + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return _this.deleteMenu({ menuId: row.menuId })
      }).then((resp) => {
        if (resp.code == 0) {
          this.getList()
          this.msgSuccess('删除成功')
        } else {
          this.msgError(resp.msg)
        }
      }).catch(function() {
      })
    }
上一篇 下一篇

猜你喜欢

热点阅读