Vue.js in laravel5.4 framework realizes error verification of Ajax form submission.

01-28-2024

The content shared by this article is about the error verification of Ajax form submission by vue.js in laravel5.4 framework, which has certain reference value and hopes to help friends in need. Prepare the development environment before you start. We assume that you have installed Laravel. As for the introduction of Vue, please refer to the official documentation.

After doing the above preparations, we can start our development. In this tutorial, we will demonstrate the form verification of the article publishing page.

First, add two routing rules in routes/web.php:

Route::get('post/create', 'PostController@create'); Route::post('post/save', 'PostController@save');

Then run the Artisan command in the root directory of the project to create the controller PostController:

php artisan make:controller PostController

Two new methods are added to the generated controller to handle routing requests:

public function create() { return view('post.create'); } public function save(Request $request) { //Set verification rules $this->validate($request,

Fill in nothing, click the Create button, and the page will display the error message:

Fill in the corresponding fields before submitting, and the creation will be successful.

In this way, we have completed a simple Ajax form submission verification function based on Vue in Laravel, and personally feel that it is still remarkable in improving development efficiency.

Related recommendations:

Laravel's new feature, high-order messaging

Realization of ACL user authorization and authority check function in Laravel 5.1 framework

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us