小编Afi*_*sli的帖子

Laravel 7 Vue 2 Sanctum 登录错误 419;CSRF 令牌不匹配

我使用 Laravel 与 Vue 的默认集成(不是使用 Vue CLI 的单独项目)。我正在尝试对用户进行身份验证,但它始终显示 419 错误。我已将 csrf 令牌包含到 Axios 的标头中,但它仍然提供不匹配错误。

引导程序.js

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)

内核.php

'api' => [
    EnsureFrontendRequestsAreStateful::class,
    'throttle:60,1',
    \Illuminate\Routing\Middleware\SubstituteBindings::class,
]
Run Code Online (Sandbox Code Playgroud)

cors.php

'paths' => [
    'api/*',
    '/login',
    '/logout',
    '/sanctum/csrf-cookie'
],
.
.
.
'supports_credentials' => true,
Run Code Online (Sandbox Code Playgroud)

网页.php

Route::get('/{any?}', function() {
    return view('welcome');
});

Route::post('/login', 'AuthController@login');
Route::post('/logout', 'AuthController@logout');
Run Code Online (Sandbox Code Playgroud)

登录Modal.vue

<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)

csrf laravel single-page-application vue.js laravel-sanctum

6
推荐指数
1
解决办法
8499
查看次数

纯javascript检测数字输入值的变化

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 来检查所做的任何更改

html javascript dom-events

2
推荐指数
1
解决办法
9784
查看次数