vue axiosを使用してリクエストバンドにクッキーを設定
713 ワード
axiosのデフォルトリクエストはクッキーを持たないので、自分で設定する必要があります.
方法1:グローバル設定:
メールでjsエントリファイル構成
方法2:使用時の設定:
方法1:グローバル設定:
メールで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)
})
}