提交 b473d8b9 编写于 作者: Z zhaoss

2.5.1小节习题、关键字添加

上级 84eadf3a
{
"node_id": "vue-dac12f88489d42e7a672eed38687cb71",
"keywords": [],
"keywords": [
"axios的基本用法",
"axios用法",
"axios是什么"
],
"children": [],
"export": [],
"keywords_must": [],
"export": [
"exercises.json"
],
"keywords_must": [
"axios"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"type": "code_options",
"author": null,
"source": "exercises.md",
"notebook_enable": false,
"exercise_id": "5d42d6e847b7470eba4c4f08ffa51079"
}
\ No newline at end of file
# axios的基本用法
<div style="color: pink;font-size:22px;font-weight:700">小常识:</div>
<br>
Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中。我们常用在Vue项目中去请求后端接口获取数据;
<br/>
![在这里插入图片描述](https://img-blog.csdnimg.cn/1f1c548bc9204941bae15c7b58e838df.png)
<br/>
<br>
安装使用 npm:
```php
$ npm install axios
```
使用 bower:
```php
$ bower install axios
```
使用 cdn:
```php
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
```
<br>
**案例**
<br>
执行 GET 请求
```javascript
// 为给定 ID 的 user 创建请求
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
// 上面的请求也可以这样做
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
```
执行 POST 请求
```javascript
axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
```
执行多个并发请求
```javascript
function getUserAccount() {
return axios.get('/user/12345');
}
function getUserPermissions() {
return axios.get('/user/12345/permissions');
}
axios.all([getUserAccount(), getUserPermissions()])
.then(axios.spread(function (acct, perms) {
// 两个请求现在都执行完成
}));
```
<br>
<div style="color: #8E7CC3;font-size:22px;font-weight:700">小测试:</div>
请将这句话补充完整:axios 的是一种`(__1__)`请求,用法和ajax类似,安装npm install axios --save 即可使用,请求中包括`(__2__)`等五种请求方式<br/><br/>
## 答案
1、异步;2、get,post,put, patch ,delete
## 选项
### A
1、同步;2、get,post,put, patch ,delete
### B
1、异步;2、get,post,put, play,delete
### C
1、同步;2、get,post,put, play,delete
{
"node_id": "vue-ff50175115364975b4695a047eaf5aad",
"keywords": [],
"keywords": [
"axios配置",
"axios请求",
"axios请求参数"
],
"children": [],
"export": [],
"keywords_must": [],
"export": [
"exercises.json"
],
"keywords_must": [
"axios"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "vue-f9bf772e800842deb661d5417adfdf43",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "vue-3231390f6d2647c793a53732cb52a70d",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
......@@ -2,7 +2,9 @@
"node_id": "vue-0475f47465fa439aa1b67eef8b281b51",
"keywords": [],
"children": [],
"export": [],
"export": [
"exercises.json"
],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
......@@ -2,7 +2,9 @@
"node_id": "vue-592ae91f67a443dca4b80a9611360c0a",
"keywords": [],
"children": [],
"export": [],
"export": [
"exercises.json"
],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
......@@ -2,7 +2,9 @@
"node_id": "vue-f7c73ed8889a4d56ab803228bb532ca9",
"keywords": [],
"children": [],
"export": [],
"export": [
"exercises.json"
],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "vue-35b90aa83701425696c832b4da590cc6",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
......@@ -2,7 +2,9 @@
"node_id": "vue-b5fd0da867d74041a258647cd1f2b688",
"keywords": [],
"children": [],
"export": [],
"export": [
"exercises.json"
],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "vue-be7de8061d2443dead0d472870a1fa1b",
"keywords": [],
"children": [],
"export": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册