最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue前端如何實(shí)現(xiàn)與后端進(jìn)行數(shù)據(jù)交互

 更新時(shí)間:2022年03月29日 14:37:30   作者:聽(tīng)聽(tīng)那晚風(fēng)  
這篇文章主要介紹了Vue前端如何實(shí)現(xiàn)與后端進(jìn)行數(shù)據(jù)交互,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

vue前端與后端數(shù)據(jù)交互

安裝

npm install axios --save

在main.js文件引入

import Axios from 'axios';//后臺(tái)交互
Vue.prototype.$http=Axios
//defaults 設(shè)置全局默認(rèn)路徑
Axios.defaults.baseURL="/"

使用

//第一種
this.$http.post('/index/customer/',{//里面寫(xiě)要傳的值}).then(function(res) {
?? ?// console.log('這是返回的客戶數(shù)據(jù)');
?? ?// console.log(res.data.data);
?? ?this.customerArr = res.data.data
});//如果是get請(qǐng)求就把post換成get
//第二種,推薦使用該方法
this.$http({
?? ??? ??? ??? ?url: '/index/patchBase/',
?? ??? ??? ??? ?method: 'get',
?? ??? ??? ??? ?headers: { 'X-Requested-With': 'XMLHttpRequest' },
?? ??? ??? ??? ?params:{}//傳值 如:params:{id:1,name:"gw"}
?? ??? ??? ?}).then(res => {
?? ??? ??? ??? ?console.log('數(shù)據(jù)接收');
?? ??? ??? ??? ?console.log(res.data.data);
?? ??? ??? ?});
this.$http({
?? ??? ??? ??? ?url: '/index/patchBase/',
?? ??? ??? ??? ?method: 'post',
?? ??? ??? ??? ?headers: { "Content-Type": "multipart/form-data" },
?? ??? ??? ??? ?data:{}//傳值
?? ??? ??? ?}).then(res => {
?? ??? ??? ??? ?console.log('數(shù)據(jù)接收');
?? ??? ??? ??? ?console.log(res.data.data);
?? ??? ??? ?});

需要注意的是 post、get請(qǐng)求的請(qǐng)求頭數(shù)據(jù)不一樣,傳值方法不一樣:get是params,post請(qǐng)求是用data傳值 

啟動(dòng)vue和前后端連接

直接上圖

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

马关县| 黄陵县| 河西区| 许昌县| 班玛县| 泉州市| 页游| 河曲县| 红安县| 临沂市| 包头市| 云梦县| 靖宇县| 宝兴县| 大荔县| 东源县| 乐都县| 新沂市| 金门县| 江阴市| 墨竹工卡县| 卢氏县| 佳木斯市| 重庆市| 若尔盖县| 苏尼特右旗| 昔阳县| 阿拉善右旗| 皮山县| 万源市| 都匀市| 天等县| 石棉县| 阜城县| 青川县| 获嘉县| 安吉县| 宽城| 安康市| 湖南省| 和平县|