📜  在 fetch() 或 get()(在 axios 中获取)方法之后直接使用哪种方法? - Javascript代码示例

📅  最后修改于: 2022-03-11 15:01:59.810000             🧑  作者: Mango

代码示例1
import axios from 'axios'
const data = axios.get('https://jsonplaceholder.typicode.com/posts')
                .then(response => response.json())    // convert response to json which is again a promise
                .then(data => console.log(data)) // get the final required data and do anything with it
                .catch(error => console.error(error)) // catch error if it occurs in any of above 2 lines of code