vue/cli axios post的使用及Authorization值傳遞
main.js引用:
import axios from 'axios';
Vue.prototype.$http = axios;
axios.defaults.baseURL = "http://localhost:8080/";
程式中使用:
let header = {
headers: {
"Access-Control-Allow-Origin": "*", //解決cors頭問題
"Access-Control-Allow-Credentials": "true", //解決session問題
"Content-Type":
"application/x-www-form-urlencoded; charset=UTF-8", //将表單資料傳遞轉化為form-data類型
Authorization: "hezhongxia",
},
withCredentials: true, //此處不使用,采用nginx 時,post接收不了資料
};
let url = "/userlogin";
this.$http.get(url, this.loginForm, header).then(function (rep) {
console.log(rep);
});