axios發(fā)送post請(qǐng)求帶參數(shù) axios發(fā)送post請(qǐng)求?
axios發(fā)送post請(qǐng)求?// post 數(shù)據(jù)let postData = { username: "user1", password: "123" }axios.post("/login", po
axios發(fā)送post請(qǐng)求?
// post 數(shù)據(jù)let postData = { username: "user1", password: "123" }axios.post("/login", postData) .then(response => { // post 成功,response.data 為返回的數(shù)據(jù) console.log(response.data) }) .catch(error => { // 請(qǐng)求失敗 console.log(error) })
怎么設(shè)置axios的全局請(qǐng)求參數(shù)?
vue.js 1.0 我們常使用 vue-resource (官方ajax庫), vue 2.0 發(fā)布后作者宣告不再對(duì) vue-resource 進(jìn)行更新, 推薦我們使用 axios (基于 promise 的 http 請(qǐng)求客戶端,可同時(shí)在瀏覽器和 node.js 中使用)
安裝 axios
使用 npm
npm install axios
使用 yarn
yarn add axios
使用 axios
如同使用 vue-resource 一樣使用
main.js
import axios from "axios" vue.prototype.$http = axios
執(zhí)行 get 請(qǐng)求
this.$http.get("/user?id=12345") .then(function (response) { console.log(response) }) .catch(function (error) { console.log(error) })
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。