使用 npm 安装
$ npm install axios
使用bower安装
$ bower install axios
使用yarn安装
$ yarn add axios
使用cdn:
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
使用
npm包地址:https://www.npmjs.com/package/axios
//node项目中使用
const axios = require('axios');
//推荐使用下面的方法(记住这一个就够用了,更换method适应不同请求和数据发送)
//更多方法可以参照 :https://www.npmjs.com/package/axios
axios({
method:'post', //支持方法:get,post,put,delete,pathc,options,head
url:'http://localhost:3000/api/setdata',
data:{key:value,.....}
}).then(res=>{
console.log(res); //res为后台返回的数据
})
模板/静态页面中使用
//引入
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
axios({
method:'post', //支持方法:get,post,put,delete,pathc,options,head
url:'http://localhost:3000/api/setdata',
data:{key:value,.....}
}).then(res=>{
console.log(res); //res为后台返回的数据
})
<input name="file" type="file" accept="image/png,image/gif,image/jpeg" @change="update"/>
---
import axios from 'axios'
// 添加请求头
update