Paste_Image.png
this.$axios({})
axios跨域問(wèn)題解決
vue-cli的config里的index.js文件里有一個(gè)參數(shù)叫proxyTable
proxyTable: {
'/api':{
target:'http://219.138.145.116:9872/WXOA/',
changeOrigin:true,
pathRewrite:{
'/api':''
}
},
'/ms':{
target: 'http://219.138.145.116:9872/WXOA/',
changeOrigin: true
}
},
頁(yè)面調(diào)用接口的時(shí)候 這樣使用
this.$axios.get(
'/api/sy_login/login.do?',
param //param為參數(shù)
)
.then(function (response) {
})
.catch(function (error) {
});
這樣當(dāng)我們?cè)L問(wèn)
localhost:8080/api/movie
的時(shí)候 其實(shí)我們?cè)L問(wèn)的是
http://api.douban.com/v2/movie
axiosPOST提交
這樣提交param后臺(tái)接收不到參數(shù)
this.$axios.get(
'/api/sy_login/login.do?',
param //param為參數(shù)
)
.then(function (response) {
})
.catch(function (error) {
});
需要引入qs
qs.stringify(param)
Paste_Image.png
該問(wèn)題是因?yàn)槟_手架工具默認(rèn)監(jiān)聽(tīng)的是8080端口绩卤,此時(shí)是8080端口被占用情況導(dǎo)致的腌紧。
找出8080端口占用進(jìn)程然后殺死
執(zhí)行sudo lsof -i :8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 79 root 6u IPv6 0x16935b8002e27567 0t0 TCP *:http-alt (LISTEN)
執(zhí)行sudo kill -9 79
再執(zhí)行sudo npm run dev,然后搭建成功.
引入全局函數(shù)
import http from './util/http';
Vue.prototype.$http = http;
export default {
get(){},
post(){}
}