ES6---继续RESTful
程序员文章站
2022-03-22 20:45:34
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.
推荐阅读
-
艾维离开苹果原因曝光:团队不愿配合管理层继续对现有产品增量更新
-
Win10 19H1继续调优开始菜单:鼠标悬停即可自动展开二级目录
-
springMVC对RESTful的支持
-
小米6用户可继续当钉子户 雷军:米10供货紧张 让想买朋友先买
-
卢伟冰:苹果如果继续标配5W充电器 市场份额还会持续下滑
-
台积电拿到美国许可 继续供货华为?官方回应:不回应
-
Win10创造者更新15019预览版本周推送:继续完善游戏模式
-
继续领跑家电全渠道第一,618大促苏宁交出满意成绩单
-
javaweb各种框架组合案例(六):springboot+spring data jpa(hibernate)+restful
-
js和jquery中循环的退出和继续下一个循环