我收到一个"419(未知状态)"错误 信息是"CSRF代号不匹配"
POST http://127.0.0.1:800/login 419(未知状态)
“https://i.stack.imgur.com/9L6si.png' rel=“noreferrer'>CSRF象征性不匹配。
Laravel 服务器:http://127.0.0.1:800
Vue 服务器 : http://localhost:8080
App/Http/Kernel.php 应用/Http/Kernel.php
api => [
LaravelSanctumHttpMiddlewareEnsureFrontendRequestsAreStateful::class,
throttle:api ,
IlluminateRoutingMiddlewareSubstituteBindings::class,
],
应用/模式/用户.php
<?php
namespace AppModels;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateNotificationsNotifiable;
use LaravelSanctumHasApiTokens;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
//...
}
配置/cors.php
<?php
return [
paths => [
api/* ,
sanctum/csrf-cookie ,
register ,
login ,
],
allowed_methods => [ * ],
allowed_origins => [ * ],
allowed_origins_patterns => [],
allowed_headers => [ * ],
exposed_headers => [],
max_age => 0,
supports_credentials => true,
];
. env. env
SESSION_DRIVER=cookie
SESSION_DOMAIN=localhost
SANCTUM_STATEFUL_DOMAINS=localhost:8080
rc/main.js
axios.interceptors.request.use((config) => {
config.baseURL = http://127.0.0.1:8000
config.withCredentials = true
return config
})
src/views/auth/login.vue 观测/观测/下水道/下水道
import axios from axios
import { reactive } from @vue/reactivity ;
export default {
setup() {
const credential = reactive({
email: ,
password: ,
})
const login = async () => {
axios.get( /sanctum/csrf-cookie ).then( async () => {
let response = await axios.post( /login , credential)
console.log(response);
});
}
return { login, credential }
}
};