axiosのデフォルトの要求は、クッキーを持って、あなたは自分自身を設定する必要はありません
方法の一つ:グローバル設定:
main.jsエントリファイル構成で
import axios from 'axios'
// 全局设置 axios 发送请求带上cookie
axios.defaults.withCredentials = true
方法2:使用設定:
login(){ //登录方法 由子组件回调
var params = {
account: this.account,
password: this.password
}
this.$http.post(
"/api/admin/login",
this.$qs.stringify(params),
{withCredentials: true}) //调用时设置 请求带上cookie
.then(function (response) {
console.log(response)
})
.catch(function (error) {
console.log(error)
})
}