一、功能
- 在瀏覽器中發送 XMLHttpRequests 請求
- 在 node.js 中發送 http請求
- 支持 Promise API
- 攔截請求和響應
- 轉換請求和響應數據
- 自動轉換 JSON 數據
- 客戶端支持保護安全免受 XSRF 攻擊
二、安裝引用
npm install axios
在main.js中
import axios from 'axios'
Vue.prototype.$http = axios
三、使用
發送get請求:
this.$http.get(this.submitUrl, {
params: {
name: this.admin.username,
pass: this.admin.pass
}
})
.then((res) => {
console.log(res);
})
.catch((res) => {
console.log(res);
})
發送post請求:
let book={
bname:this.product.bname,
author:this.product.author
}
this.$http.post(this.addUrl,book)
.then((res)=>{
console.log(res);
})