好,下面上貨。
創(chuàng)新互聯(lián)專注于大寧網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供大寧營(yíng)銷型網(wǎng)站建設(shè),大寧網(wǎng)站制作、大寧網(wǎng)頁(yè)設(shè)計(jì)、大寧網(wǎng)站官網(wǎng)定制、小程序設(shè)計(jì)服務(wù),打造大寧網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供大寧網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。
1、安裝axios
npm install axios --save
2、添加axios組件
import axios from 'axios' axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'; axios.defaults.baseURL = 'http://localhost:7878/zkview'; Vue.prototype.$ajax = axios;
3、get請(qǐng)求
testGet: function () { this.$ajax({ method: 'get', url: '/test/greeting', params: { firstName: 'Fred', lastName: 'Flintstone' } }).then(function (response) { console.log(response); }).catch(function (error) { console.log(error); }); },
4、post請(qǐng)求
testPost: function () { var params = new URLSearchParams(); params.append('name', 'hello jdmc你好'); params.append('id', '2'); this.$ajax({ method: 'post', url: '/test/greeting2', data:params // data: {id: '3', name: 'abc'} }).then(function (response) { console.log(response); }).catch(function (error) { console.log(error); }) }
5、運(yùn)行結(jié)果:
6、注意:
在使用post方式的時(shí)候傳遞參數(shù)有兩種方式,一種是普通方式,一種是json方式,如果后臺(tái)接受的是普通方式,那么使用上述方式即可。
普通的formed方式
var params = new URLSearchParams(); params.append('name', 'hello jdmc你好'); params.append('id', '2'); data:params
后臺(tái)接收參數(shù):
public Student greeting2(int id,String name) {
json方式
data: {id: '3', name: 'abc'}
后臺(tái)接收參數(shù)
public Object greeting2(@RequestBody Object student) {
以上這篇基于vue 添加axios組件,解決post傳參數(shù)為null的問(wèn)題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持創(chuàng)新互聯(lián)。
分享題目:基于vue添加axios組件,解決post傳參數(shù)為null的問(wèn)題
文章源于:http://muchs.cn/article22/ijcejc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、建站公司、域名注冊(cè)、網(wǎng)站內(nèi)鏈、微信小程序、網(wǎng)站建設(shè)
聲明:本網(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)
移動(dòng)網(wǎng)站建設(shè)知識(shí)