Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

vue跨域请求请求头中无cookie

由于某些原因 需要跨域传cookie 如页面地址是 foo.com 服务端接口地址是 bar.com
Nginx已经做了如下配置

add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Origin $http_origin;

前端(vue)也配置了withCredentials: true

<script>
  new Vue({
    el: '#app',
    data: {
      url: 'https://bar.com/...',
      message: ''
    },
    methods: {

    },
    created() {
      axios
        .get(this.url, {
          withCredentials: true
        })
        .then((result) => {
          this.message = JSON.stringify(result, null, 4)
          console.log(JSON.stringify(result, null, 4))
        })
    }
  })
</script>

接口能正常调用 但是请求头中根本就没有cookie这一项

是不是根本就不支持呢 ?还是说还需要哪些额外的配置呢


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

withCredentials 只会传 bar.com 的 cookies,你是不是想传 foo.com 的 cookies ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...