axios 无法跨域问题解决

参考

https://learnku.com/laravel/t/12584/unable-to-cross-domain-axios-get-x-csrf-token-does-not-allow-access-control-allow-headerss-preflight-response

https://learnku.com/articles/6504/laravel-cross-domain-solution

服务端

server('HTTP_ORIGIN') ? $request->server('HTTP_ORIGIN') : '';
        $allow_origin = [
            'http://localhost:8000',
        ];
        if (in_array($origin, $allow_origin)) {
            $response->header('Access-Control-Allow-Origin', $origin);
            $response->header('Access-Control-Allow-Headers', 'Origin, Content-Type, Cookie, X-CSRF-TOKEN, Accept, Authorization, X-XSRF-TOKEN');
            $response->header('Access-Control-Expose-Headers', 'Authorization, authenticated');
            $response->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, OPTIONS');
            $response->header('Access-Control-Allow-Credentials', 'true');
        }
        return $response;
    }
}

你可能感兴趣的:(axios 无法跨域问题解决)