ES6---继续RESTful
程序员文章站
2022-07-09 19:46:56
ES6 继续RESTful 1. POST请求,添加数据 function addTodo() { console.log('POST 请求'); axios.post('http://jsonplaceholder.typicode.com/todos', { "title": "xiaomin ......
es6---继续restful
1. post请求,添加数据
function addtodo() { console.log('post 请求'); axios.post('http://jsonplaceholder.typicode.com/todos', { "title": "xiaomin is reading", "completed": false }).then(result => { console.log(result); }).catch(error => console.log(error)); }
console:
2. put,在url后面加上id
//put/patch请求 function updatetodo() { console.log('put/patch请求'); axios.put('http://jsonplaceholder.typicode.com/todos/1', { title: "xiaomin is reading", completed: false }).then(result => { console.log(result); }).catch(error => { console.log(error); }) }
console:
3. patch请求
//put/patch请求 function updatetodo() { console.log('put/patch请求'); axios.patch('http://jsonplaceholder.typicode.com/todos/1', { userid: 1, title: "xiaomin is reading", completed: false }).then(result => { console.log(result); }).catch(error => { console.log(error); }) }
console:
4. delete
//delete请求 function removetodo() { console.log('delete 请求'); //ajax里面是 url?id=1 ===>url/1 axios.delete('http://jsonplaceholder.typicode.com/todos/1') .then(result => { console.log(result); }) .catch(error => { console.log(error); }) }
console:
5. 批量请求数据
//批量请求数据 function getdata() { console.log('批量请求数据'); axios.all([ axios.get('file:///c:/users/administrator/desktop/bstudy/1111.json'), axios.get('file:///c:/users/administrator/desktop/bstudy/1112.json') ]).then(result => { console.log(result); }); }
console:
6.
//批量请求数据 function getdata() { console.log('批量请求数据'); axios.all([ axios.get('file:///c:/users/administrator/desktop/bstudy/1111.json'), axios.get('file:///c:/users/administrator/desktop/bstudy/1112.json') ]).then(axios.spread((a1, a2) => { //分发数据 console.log(a1.data); console.log(a2.data); })) }
console:
7.
推荐阅读