1. 当我们用axios发送请求后,catch到错误请求时需要对error数据内容了解,才可以进行储物分类展示等操作

    我们可以通过Object.keys()方法获取当前的error的key,然后再对各个内容进行学习

    Untitled

    返回值如下:

    Untitled

    可以看到error是一个object对象,并且包含config、request、response、isAxiosError、toJSON等键。

    error.response

    error.response中包含config、request。我们后端返回数据会在error.response.data中

    Untitled

    error.toJSON

    Untitled

    error.toJSON包含的信息也较多。let {message} = error ;  等同于error.toJSON.message