0

我们在 axios.js 中为 axion 请求声明了默认的 Authorization 标头。它第一次工作,但是当我刷新页面时它给出了500 internal server 错误。

这是我在 axios.js 中声明它的方式

// axios
import axios from 'axios'

alert(localStorage.getItem('accessToken'))
const baseURL = ''
axios.defaults.headers.common = { 'Authorization': localStorage.getItem('accessToken') }
export default axios.create({
    baseURL
    // You can add your headers here
})

Laravel api 路由

Route::group(['middleware' => 'auth:api'], function () {
    Route::group(['prefix' => 'user'], function () {
        Route::get('/all_users', 'User\UserController@index');
    });
});

这是回应

Symfony\Component\Routing\Exception\RouteNotFoundException: Route [login] not defined. in file C:\projects\logistics-portal\vendor\laravel\framework\src\Illuminate\Routing\UrlGenerator.php on line 420
4

1 回答 1

0

你的失踪Bearer

所以像这样添加

axios.defaults.headers.common = { 'Authorization': 'Bearer '+localStorage.getItem('accessToken') }
于 2020-11-02T11:58:25.830 回答