小編給大家分享一下vue中如何實(shí)現(xiàn)基于axios的ajax請(qǐng)求方法,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
成都創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),武侯企業(yè)網(wǎng)站建設(shè),武侯品牌網(wǎng)站建設(shè),網(wǎng)站定制,武侯網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,武侯網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
如下所示:
import Vue from 'vue' let service = { url: 'http://host.xxxxx.com/xxx.php' } service.ajaxReuqest = (url, options, type, fileFlag) => { for (const i in options) { if (!options[i] && options[i] !== 0 && (options[i].length && options[i].length > 0)) { delete options[i] } } let promise = new Promise((resolve, reject) => { if (fileFlag) { Vue.axios.post(url, options, { headers: { 'Content-Type': 'multipart/form-data' } }).then((res) => { resolve(res) }) } else if (type === 'GET') { Vue.axios.get(url, { params: options }).then((res) => { resolve(res.data.resultObj) }).then((err) => { reject(err) }) } else { Vue.axios.post(url, options).then((res) => { resolve(res) }).then((err) => { reject(err) }) } }) return promise }
支持POST GET請(qǐng)求以及圖片上傳,基于axios,適用于vue,
以異步獲取省份列表作為例子:
// 獲取省份信息 service.getProvinceList = (options) => { return service.ajaxRequest(service.url + '/basic/getProvinceList', options, 'POST') }
getProvinceList () { service.getProvinceList({}).then((res) => { this.provinceList = res.data.resultObj.data }) }
以上是“vue中如何實(shí)現(xiàn)基于axios的ajax請(qǐng)求方法”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
當(dāng)前標(biāo)題:vue中如何實(shí)現(xiàn)基于axios的ajax請(qǐng)求方法
當(dāng)前鏈接:http://chinadenli.net/article40/jiisho.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、電子商務(wù)、面包屑導(dǎo)航、企業(yè)網(wǎng)站制作、企業(yè)建站、Google
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)