axiosを使用してVUEの帯域設定要求クッキー

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)
        })
      }

 

公開された98元の記事 ウォン称賛26 ビュー70000 +

おすすめ

転載: blog.csdn.net/weixin_42425970/article/details/104082540