zoukankan      html  css  js  c++  java
  • VUE npm run build的项目出现跨域请求的问题npm run dev没有这个问题

    报错信息
    Access to XMLHttpRequest at 'http://platformapi-test.lih-elearning.cn/api/v1/login' from origin 'http://www.vue.com' has been blocked by CORS policy: Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.

     

     在PHP文件中设置头信息(支持多域名),例如:

    //加入跨域头信息,目前为本机地址和测试地址可通过
    $origin = isset($_SERVER['HTTP_ORIGIN'])? $_SERVER['HTTP_ORIGIN'] : '';
    $allow_origin = array(
    
    );
    if (in_array($origin, $allow_origin)) {
        header("Access-Control-Allow-Origin:" . $origin);
        header('Access-Control-Allow-Headers:Authorization, Content-Type, Depth,User-Agent, X-File-Size, X-Requested-With, X-Requested-By, If-Modified-Since, X-File-Name, X-File-Type, Cache-Control, Origin');
        header('Access-Control-Allow-Methods:GET, POST, PATCH, PUT, OPTIONS');
    }
  • 相关阅读:
    Beta 冲刺 (2/7)
    Beta 冲刺 (1/7)
    2017软件工程实践总结
    华为软件开发云评测
    android开发——用户头像
    学生&部门智能匹配程序
    学生会里学生汇
    数独棋盘生成器
    读与思
    Java接口
  • 原文地址:https://www.cnblogs.com/houss/p/11511392.html
Copyright © 2011-2022 走看看