es6里面的promise不捕获异常老是报unhandledRejection错,有啥办法不让它报么?

deleteClick1(index, row){
        var _self = this;
        this.$confirm("确认删除第" + (index+1) + "行吗?", "提示", {
          type: 'warning',
          confirmButtonText:'确认',
          cancelButtonText:'取消'
        }).then(function () {
          axios.post('/api/train/classtype/delete', {
            id:row.id,  //取该行id的值给id
          }).then(function (response) {
            console.log("row.id的值:"+row.id);
            console.log("index的值:"+index);
            console.log("删除时候返回:");
            console.log(response);
            _self.getDataTrainPage(1,8);
          })
        })
      },

es6里面的promise不捕获异常老是报unhandledRejection错,有啥办法不让它报么?_第1张图片


这就需要写catch处理,这样在调试状态下就不会捕获然后暂停了

deleteClick1(index, row){
        var _self = this;
        this.$confirm("确认删除第" + (index+1) + "行吗?", "提示", {
          type: 'warning',
          confirmButtonText:'确认',
          cancelButtonText:'取消'
        }).then(function () {
          axios.post('/api/train/classtype/delete', {
            id:row.id,  //取该行id的值给id
          }).then(function (response) {
            console.log("row.id的值:"+row.id);
            console.log("index的值:"+index);
            console.log("删除时候返回:");
            console.log(response);
            _self.getDataTrainPage(1,8);
          })
        }).catch(function (error) {//加上catch 
          console.log(error);
        })
      },

你可能感兴趣的:(Vue)