我使用 Laravel 与 Vue 的默认集成(不是使用 Vue CLI 的单独项目)。我正在尝试对用户进行身份验证,但它始终显示 419 错误。我已将 csrf 令牌包含到 Axios 的标头中,但它仍然提供不匹配错误。
window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
window.axios.defaults.withCredentials = true;
window.axios.defaults.baseURL = "http://localhost:8000/";
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = $('meta[name="csrf-token"]').attr('content');
Run Code Online (Sandbox Code Playgroud)
'api' => [
EnsureFrontendRequestsAreStateful::class,
'throttle:60,1',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
]
Run Code Online (Sandbox Code Playgroud)
'paths' => [
'api/*',
'/login',
'/logout',
'/sanctum/csrf-cookie'
],
.
.
.
'supports_credentials' => true,
Run Code Online (Sandbox Code Playgroud)
Route::get('/{any?}', function() {
return view('welcome');
});
Route::post('/login', 'AuthController@login');
Route::post('/logout', 'AuthController@logout');
Run Code Online (Sandbox Code Playgroud)
<template>
<form @submit.prevent="submit" method="POST">
<input type="text" class="form-control" placeholder="Email" v-model="email" />
<input
type="password"
class="form-control"
placeholder="Password"
v-model="password" …Run Code Online (Sandbox Code Playgroud) window.onload = function init() {
console.log("DOM is ready!");
var input, value;
input = document.getElementById("yourGuess");
input = input.value;
input.addEventListener("checking", check, false);
check(value);
}
function check(value) {
if(input < 0 && input > 10) {
alert("The number must be between 0 - 10");
value = 0;
}
}Run Code Online (Sandbox Code Playgroud)
<label for="yourGuess">You choose: </label>
<input id="yourGuess" type="number" min="0" max="10">Run Code Online (Sandbox Code Playgroud)
我在任何地方都找不到与上述问题相对应的解决方案。
所以我有一个数字类型输入,并声明了一个 min 和 max 属性,其值分别为 0 和 10。
用户可以单击输入字段并将其值更改为超出范围,因此我需要使用 javasricpt 来检查所做的任何更改