Livewire表单遇到问题!没有验证的消息?Laravel 10版本

创建了一个组件:

php artisan make:livewire SignUpForm

模块如下:

<?php

namespace App\Http\Livewire;

use Livewire\Component;

class SignUpForm extends Component
{
    public $name;
    public $email;
    public $password;
    public $password_confirmation;

    protected $rules = [
        'name' => 'required|min:3',
        'email' => 'required|email|unique:users,email',
        'password' => 'required|min:6|confirmed',
    ];

    public function updated($propertyName): void
    {
        $this->validateOnly($propertyName);
    }

    public function submitForm(): string
    {
        $this->validate();
        dd('我就看看');
    }

    public function render(): \Illuminate\Contracts\View\View|\Illuminate\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\Foundation\Application
    {
        return view('livewire.sign-up-form');
    }
}

视图如下:

<!-- /d:/larave/resources/views/livewire/sign-up-form.blade.php -->

<div>
    <form wire:submit.prevent="submitForm">
        <div class="relative flex mb-6">
            <label for="name">Name:</label>
            <input type="text" id="name" wire:model="name" autocomplete="new-password">
            @error('name') <span>{{ $message }}</span> @enderror
        </div>

        <div class="relative flex mb-6">
            <label for="email">Email:</label>
            <input type="email" id="email" wire:model="email" autocomplete="new-password">
            @error('email') <span>{{ $message }}</span> @enderror
        </div>

        <div class="relative flex mb-6">
            <label for="password">Password:</label>
            <input type="password" id="password" wire:model="password" autocomplete="new-password">
            @error('password') <span>{{ $message }}</span> @enderror
        </div>

        <div class="relative flex mb-6">
            <label for="password_confirmation">Confirm Password:</label>
            <input type="password" id="password_confirmation" wire:model="password_confirmation" autocomplete="new-password">
        </div>

        <button type="submit">Submit</button>
    </form>
</div>

页面<livewire:sign-up-form />正常渲染了表单,但是我点击提交按钮,页面闪了下,没有出现任何错误提示? 请教下各位大神是什么原因?

《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
最佳答案

问题已经解决,感谢大家帮助。

laravel 10.x 不知道是不是我安装的问题。

<html>
<head>
    ...
    @livewireStyles  <!-- 这样写没有效果 -->
</head>
<body>
    ...
    @livewireScripts <!-- 这样写没有效果 -->

    <livewire:styles  /> <!-- 这样写有效果 -->
    ...
    <livewire:scripts  /> <!-- 这样写有效果 -->
</body>
</html>
11个月前 评论
讨论数量: 5
翟宇鑫

$this->validate(); 这个接口也需要写相应的校验规则,因为这里没有验证规则,所以没有任何提示信息
submit 中没有进行相应的后续操作,所以看起来像是 form 刷新了一下

11个月前 评论
汪阿浠 (楼主) 11个月前
翟宇鑫

视图文件把首行注释删掉:<!-- /d:/larave/resources/views/livewire/sign-up-form.blade.php -->

11个月前 评论
汪阿浠 (楼主) 11个月前

问题已经解决,感谢大家帮助。

laravel 10.x 不知道是不是我安装的问题。

<html>
<head>
    ...
    @livewireStyles  <!-- 这样写没有效果 -->
</head>
<body>
    ...
    @livewireScripts <!-- 这样写没有效果 -->

    <livewire:styles  /> <!-- 这样写有效果 -->
    ...
    <livewire:scripts  /> <!-- 这样写有效果 -->
</body>
</html>
11个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!