vue 使用axios 報(bào)錯(cuò)Error: Request failed with status code 404
3 回答

森林海
TA貢獻(xiàn)2011條經(jīng)驗(yàn) 獲得超2個(gè)贊
Vue.js 1.0 我們常使用 vue-resource (官方ajax庫), Vue 2.0 發(fā)布后作者宣告不再對 vue-resource 進(jìn)行更新, 推薦我們使用 axios (基于 Promise 的 HTTP 請求客戶端,可同時(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 請求
this.$http.get('/user?ID=12345') .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助
- 3 回答
- 0 關(guān)注
- 31731 瀏覽
添加回答
舉報(bào)
0/150
提交
取消