vue中axios获取的值使用Promise用做参数引用

Vue中axios获取的值可以通过Promise再次引用

			let that = this
            new Promise(function (resolve, reject) {
                that.axios.post('/file/imgUpload', fd, 
                      {
                      headers: {
                      'Content-Type': 'multipart/form-data'
                      }
                    }).then((response) => {
                       that.imgId = response.data.data
                        resolve(that.imgId);
                    }).catch((error) =>{
                        this.$message.error('头像上传失败,请重新上传!');
                    })
                   }).then(function (id){
                   that.axios.get('/file/view/'+id)
                    .then((response) => {
                        console.log(response)
                     })
              }) 

猜你喜欢

转载自blog.csdn.net/LONGLONGAGO_RU/article/details/83339238