axios.CancelToken

 取消发送中的请求

        const CancelToken = axios.CancelToken
        window.cancle = null
        export const getImagePhoto = params => {
            return jsonRequest({
                url: '',
                method: 'get',
                params,
                cancelToken: new CancelToken(function executor (cancel) {
                    // executor 函数接收一个 cancel 函数作为参数
                    window.cancle = cancel
                })
            }).then(res => res.data)
        }
        getBusinessCardAvatar () {
            window.cancle && window.cancle()
            getImagePhoto({
                userId: this.saleNo
            }).then(res => {
                if (res.success) {
                    resolve(res)
                } else {
                    console.error(res.errorMessage)
                    resolve(res)
                }
            })
        }

 

posted @ 2022-06-30 15:07  javascript9527  阅读(266)  评论(0编辑  收藏  举报