2018-03-09

ajax使用說(shuō)明

## vue ajax庫(kù)

* 2個(gè)常用的庫(kù)

? * vue-resource: vue插件,非官方庫(kù), vue1.x使用廣泛

? * axios:通用的ajax請(qǐng)求庫(kù),官方推薦, vue2.x使用廣泛

* vue-resource基本使用

? *在線文檔: https://github.com/pagekit/vue-resource/blob/develop/docs/http.md

*下載: npm install vue-resource --save

*編碼

? ? ```

//引入模塊

? ? import VueResource from 'vue-resource'

//聲明使用插件

? ? Vue.use(VueResource)

//通過(guò)vue組件對(duì)象發(fā)送ajax請(qǐng)求

? ? this.$http.get('/someUrl').then((response) => {

// success callback

console.log(response.body) //返回結(jié)果數(shù)據(jù)

? ? }, (response) => {

// error callback

console.log(response.statusText) //錯(cuò)誤信息

? ? })

```

* axios基本使用

? * axios在線文檔: https://github.com/mzabriskie/axios

*下載axios: npm install axios --save

*編碼:

```

//引入模塊

? ? import axios from 'axios'

//發(fā)送ajax請(qǐng)求

? ? axios.get(url)

.then((response) => {

console.log(response.data) //得到返回結(jié)果數(shù)據(jù)

? ? ? })

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容