ਲੇਖ

Laravel ਅਤੇ Vue.js ਨਾਲ ਇੱਕ CRUD ਐਪ ਬਣਾਉਣਾ

ਇਸ ਟਿਊਟੋਰਿਅਲ ਵਿੱਚ ਅਸੀਂ ਇਕੱਠੇ ਵੇਖਦੇ ਹਾਂ ਕਿ Laravel ਅਤੇ Vue.js ਦੇ ਨਾਲ ਇੱਕ ਉਦਾਹਰਣ CRUD ਐਪ ਦਾ ਕੋਡ ਕਿਵੇਂ ਲਿਖਣਾ ਹੈ।

La ਸਿੰਗਲ ਪੇਜ ਐਪਲੀਕੇਸ਼ਨ ਸਾਨੂੰ DB 'ਤੇ ਬੁਨਿਆਦੀ ਕਾਰਵਾਈਆਂ ਦੇ ਇੱਕ ਚੱਕਰ ਨੂੰ ਪੂਰਾ ਕਰਨ ਦੀ ਇਜਾਜ਼ਤ ਦੇਵੇਗਾ: ਨਾਲ ਬਣਾਓ, ਪੜ੍ਹੋ, ਅੱਪਡੇਟ ਕਰੋ ਅਤੇ ਮਿਟਾਓ Vue.js , Vue ਰਾਊਟਰ ਅਤੇ Laravel ਫਰੇਮਵਰਕ .

ਅੱਜਕੱਲ੍ਹ, ਸਭ ਤੋਂ ਪ੍ਰਸਿੱਧ ਜੇਐਸ ਫਰੇਮਵਰਕ ਐਂਗੂਲਰ ਜੇਐਸ ਅਤੇ ਵਯੂ ਜੇਐਸ ਹਨ। Angular JS ਅਤੇ Vue JS ਬਹੁਤ ਹੀ ਉਪਭੋਗਤਾ-ਅਨੁਕੂਲ ਅਤੇ ਸਭ ਤੋਂ ਪ੍ਰਸਿੱਧ JS ਫਰੇਮਵਰਕ ਹਨ। ਇਹ ਪੰਨੇ ਨੂੰ ਤਾਜ਼ਾ ਕੀਤੇ ਬਿਨਾਂ ਅਤੇ ਸ਼ਕਤੀਸ਼ਾਲੀ jquery ਪ੍ਰਮਾਣਿਕਤਾ ਦੇ ਪੂਰੇ ਪ੍ਰੋਜੈਕਟ ਜਾਂ ਐਪਲੀਕੇਸ਼ਨ ਦਾ ਪ੍ਰਬੰਧਨ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ।

Vue Laravel ਦੇ ਨਾਲ ਪਹਿਲਾਂ ਤੋਂ ਪੈਕ ਕੀਤਾ ਜਾਂਦਾ ਹੈ (ਨਾਲ ਲਾਰਵੇਲ ਮਿਕਸ 'ਤੇ ਆਧਾਰਿਤ ਇੱਕ ਸ਼ਾਨਦਾਰ ਲੇਖਕ ਸੰਦ ਹੈ ਵੈਬਪੈਕ ) ਅਤੇ ਡਿਵੈਲਪਰਾਂ ਨੂੰ ਟ੍ਰਾਂਸਪਾਈਲਰ, ਕੋਡ ਪੈਕੇਜ, ਸਰੋਤ ਨਕਸ਼ੇ ਜਾਂ ਆਧੁਨਿਕ ਫਰੰਟਐਂਡ ਵਿਕਾਸ ਦੇ ਹੋਰ "ਗੰਦੇ" ਪਹਿਲੂਆਂ ਬਾਰੇ ਚਿੰਤਾ ਕੀਤੇ ਬਿਨਾਂ ਗੁੰਝਲਦਾਰ ਸਿੰਗਲ ਪੇਜ ਐਪਲੀਕੇਸ਼ਨ ਬਣਾਉਣਾ ਸ਼ੁਰੂ ਕਰਨ ਦੀ ਇਜਾਜ਼ਤ ਦਿੰਦਾ ਹੈ।

ਸਰਵਰ ਲੋੜਾਂ

ਪੀਐਚਪੀ 7.4

ਲਾਰਵੇਲ 8.x

MySQL

Laravel ਪ੍ਰੋਜੈਕਟ ਨੂੰ ਸਥਾਪਿਤ ਕਰੋ

ਪਹਿਲਾਂ, ਟਰਮੀਨਲ ਖੋਲ੍ਹੋ ਅਤੇ ਨਵਾਂ ਲਾਰਵੇਲ ਪ੍ਰੋਜੈਕਟ ਬਣਾਉਣ ਲਈ ਹੇਠ ਲਿਖੀ ਕਮਾਂਡ ਚਲਾਓ:

composer create-project --prefer-dist laravel/laravel crud-spa

ਜਾਂ, ਜੇਕਰ ਤੁਸੀਂ Laravel Installer ਨੂੰ ਇੱਕ ਕੰਪੋਜ਼ਰ ਗਲੋਬਲ ਨਿਰਭਰਤਾ ਵਜੋਂ ਸਥਾਪਿਤ ਕੀਤਾ ਹੈ:

laravel new crud-spa

ਡਾਟਾਬੇਸ ਵੇਰਵਿਆਂ ਨੂੰ ਕੌਂਫਿਗਰ ਕਰੋ:

ਇੰਸਟਾਲੇਸ਼ਨ ਤੋਂ ਬਾਅਦ ਆਪਣੀ ਪ੍ਰੋਜੈਕਟ ਰੂਟ ਡਾਇਰੈਕਟਰੀ 'ਤੇ ਜਾਓ, .env ਫਾਈਲ ਖੋਲ੍ਹੋ ਅਤੇ ਡੇਟਾਬੇਸ ਵੇਰਵੇ ਨੂੰ ਹੇਠਾਂ ਦਿੱਤੇ ਅਨੁਸਾਰ ਸੈੱਟ ਕਰੋ:

DB_CONNECTION=mysql 
DB_HOST=127.0.0.1 
DB_PORT=3306 
DB_DATABASE=<DATABASE NAME>
DB_USERNAME=<DATABASE USERNAME>
DB_PASSWORD=<DATABASE PASSWORD>

npm ਨਿਰਭਰਤਾਵਾਂ ਨੂੰ ਸਥਾਪਿਤ ਕਰੋ

ਫਰੰਟ-ਐਂਡ ਨਿਰਭਰਤਾਵਾਂ ਨੂੰ ਸਥਾਪਿਤ ਕਰਨ ਲਈ ਹੇਠ ਦਿੱਤੀ ਕਮਾਂਡ ਚਲਾਓ:

npm install

ਇਸ ਤੋਂ ਬਾਅਦ, ਇੰਸਟਾਲ ਕਰੋ ਝਲਕ ,  vue-ਰਾਊਟਰ  e vue-axios . Vue-axios ਦੀ ਵਰਤੋਂ Laravel ਬੈਕਐਂਡ API ਨੂੰ ਕਾਲ ਕਰਨ ਲਈ ਕੀਤੀ ਜਾਵੇਗੀ। ਟਰਮੀਨਲ 'ਤੇ ਹੇਠ ਦਿੱਤੀ ਕਮਾਂਡ ਚਲਾਓ:

npm install vue vue-router vue-axios --save

ਮਾਈਗ੍ਰੇਸ਼ਨ, ਮਾਡਲ ਅਤੇ ਕੰਟਰੋਲਰ ਬਣਾਓ

ਇੱਕ ਸ਼੍ਰੇਣੀ ਟੈਮਪਲੇਟ, ਮਾਈਗ੍ਰੇਸ਼ਨ, ਅਤੇ ਕੰਟਰੋਲਰ ਬਣਾਓ। ਇਸਦੇ ਲਈ ਹੇਠ ਦਿੱਤੀ ਕਮਾਂਡ ਚਲਾਓ:

php artisan make:model Category -mcr

-mcr  ਇਹ ਵਿਸ਼ਾ ਸਿੰਗਲ ਕਮਾਂਡ ਸਿੰਥੇਸਿਸ ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਮਾਡਲ, ਮਾਈਗ੍ਰੇਸ਼ਨ ਅਤੇ ਕੰਟਰੋਲਰ ਬਣਾਏਗਾ।

ਹੁਣ, ਤੋਂ ਸ਼੍ਰੇਣੀ ਮਾਈਗ੍ਰੇਸ਼ਨ ਫਾਈਲ ਨੂੰ ਖੋਲ੍ਹੋ ਡਾਟਾਬੇਸ / ਮਾਈਗ੍ਰੇਸ਼ਨ ਅਤੇ ਕੋਡ ਨੂੰ ਫੰਕਸ਼ਨ ਵਿੱਚ ਬਦਲੋ ਉੱਪਰ() :

public function up()
{
    Schema::create('categories', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('title');
        $table->text('description');
        $table->timestamps();
    });
}

ਹੇਠ ਦਿੱਤੀ ਕਮਾਂਡ ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਡੇਟਾਬੇਸ ਨੂੰ ਮਾਈਗਰੇਟ ਕਰੋ:

php artisan migrate

ਹੁਣ, Category.php ਟੈਂਪਲੇਟ ਨੂੰ ਖੋਲ੍ਹੋapp/Models  ਅਤੇ ਫਾਈਲ ਵਿੱਚ ਕੋਡ ਨੂੰ ਸੋਧੋ model Category.php :

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Category extends Model {

   use HasFactory;

   protected $fillable = ['title','description'];

}

?>

ਉਸ ਤੋਂ ਬਾਅਦ, ਖੋਲ੍ਹੋ CategoryController.php ਅਤੇ ਇੰਡੈਕਸ, ਸਟੋਰ, ਅੱਪਡੇਟ ਅਤੇ ਮਿਟਾਉਣ ਦੇ ਤਰੀਕਿਆਂ ਵਿੱਚ ਕੋਡ ਸ਼ਾਮਲ ਕਰੋ:

<?php

namespace App\Http\Controllers;

use App\Models\Category;
use Illuminate\Http\Request;

class CategoryController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $categories = Category::all(['id','title','description']);
        return response()->json($categories);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $category = Category::create($request->post());
        return response()->json([
            'message'=>'Category Created Successfully!!',
            'category'=>$category
        ]);
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Models\Category  $category
     * @return \Illuminate\Http\Response
     */
    public function show(Category $category)
    {
        return response()->json($category);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Category  $category
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Category $category)
    {
        $category->fill($request->post())->save();
        return response()->json([
            'message'=>'Category Updated Successfully!!',
            'category'=>$category
        ]);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\Category  $category
     * @return \Illuminate\Http\Response
     */
    public function destroy(Category $category)
    {
        $category->delete();
        return response()->json([
            'message'=>'Category Deleted Successfully!!'
        ]);
    }
}

Defiweb.php ਵਿੱਚ ਰੂਟਾਂ ਨੂੰ ਪੂਰਾ ਕਰੋ

ਓਰਾ defiਉਹਨਾਂ ਨੂੰ ਖਤਮ ਕਰੋ routes ਫਾਈਲਾਂ ਵਿੱਚ web.php e api.php . ਫੋਲਡਰ 'ਤੇ ਜਾਓ routes ਅਤੇ web.php ਅਤੇ api.php ਫਾਈਲ ਖੋਲ੍ਹੋ ਅਤੇ ਹੇਠਾਂ ਦਿੱਤੇ ਨੂੰ ਅਪਡੇਟ ਕਰੋ routes:

routes/web.php

ਇਨੋਵੇਸ਼ਨ ਨਿਊਜ਼ਲੈਟਰ
ਨਵੀਨਤਾ ਬਾਰੇ ਸਭ ਤੋਂ ਮਹੱਤਵਪੂਰਨ ਖ਼ਬਰਾਂ ਨੂੰ ਨਾ ਭੁੱਲੋ। ਉਹਨਾਂ ਨੂੰ ਈਮੇਲ ਦੁਆਰਾ ਪ੍ਰਾਪਤ ਕਰਨ ਲਈ ਸਾਈਨ ਅੱਪ ਕਰੋ।
<?php
 
Route::get('{any}', function () {
    return view('app');
})->where('any', '.*');

routes/api.php

<?php
 
Route::resource('category',App\Http\Controllers\CategoryController::class)->only(['index','store','show','update','destroy']);

ਇੱਕ Vue ਐਪ ਬਣਾਓ

ਇਸ ਪਗ ਵਿੱਚ, ਡਾਇਰੈਕਟਰੀ ਵਿੱਚ ਜਾਓ ਸਰੋਤ/ਵਿਯੂਜ਼, ਫਾਈਲ ਬਣਾਓ app.blade.php  ਅਤੇ ਹੇਠ ਦਿੱਤੇ ਕੋਡ ਨੂੰ ਸ਼ਾਮਲ ਕਰੋ app.blade.php:

<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="csrf-token" value="{{ csrf_token() }}"/>
        <title>Laravel Vue CRUD App</title>
        <link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet" type="text/css">
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
        <link href="{{ mix('css/app.css') }}" type="text/css" rel="stylesheet"/>
    </head>
    <body>
        <div id="app">
        </div>
        <script src="{{ mix('js/app.js') }}" type="text/javascript"></script>
    </body>
</html>

Vue ਐਪ ਲਈ ਕੰਪੋਨੈਂਟ ਬਣਾਓ

ਇਸ ਕਦਮ ਵਿੱਚ, ਫੋਲਡਰ ਵਿੱਚ ਜਾਓ resource/js, ਫੋਲਡਰ ਬਣਾਓ components  ਅਤੇ ਹੇਠ ਲਿਖੇ ਅਨੁਸਾਰ ਫਾਈਲਾਂ ਬਣਾਓ:

  • View app
  • Welcome.vue
  • Category/List.vue
  • Category/Add.vue
  • Category/Edit.vue

ਐਪ। vue  ਇਹ ਸਾਡੀ Vue ਐਪ ਦੀ ਮੁੱਖ ਫਾਈਲ ਹੈ। Defiਅਸੀਂ ਖਤਮ ਕਰਾਂਗੇ ਰਾਊਟਰ-ਦ੍ਰਿਸ਼  ਉਸ ਫਾਈਲ ਵਿੱਚ. ਸਾਰੇ ਮਾਰਗ ਫਾਈਲ ਵਿੱਚ ਦਿਖਾਈ ਦੇਣਗੇ ਐਪ। vue  .

ਫਾਈਲ ਖੋਲ੍ਹੋ Welcome.vue ਅਤੇ ਉਸ ਫਾਈਲ ਵਿੱਚ ਹੇਠਾਂ ਦਿੱਤੇ ਕੋਡ ਨੂੰ ਅਪਡੇਟ ਕਰੋ:

<template>
    <div class="container mt-5">
        <div class="col-12 text-center">
            <h1>Laravel Vuejs CRUD</h1>
        </div>
    </div>
</template>

App.vue ਫਾਈਲ ਖੋਲ੍ਹੋ ਅਤੇ ਕੋਡ ਨੂੰ ਹੇਠਾਂ ਦਿੱਤੇ ਅਨੁਸਾਰ ਅਪਡੇਟ ਕਰੋ:

<template>
    <main>
        <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
            <div class="container-fluid">
                <router-link to="/" class="navbar-brand" href="#">Laravel Vue Crud App</router-link>
                <div class="collapse navbar-collapse">
                    <div class="navbar-nav">
                        <router-link exact-active-class="active" to="/" class="nav-item nav-link">Home</router-link>
                        <router-link exact-active-class="active" to="/category" class="nav-item nav-link">Category</router-link>
                    </div>
                </div>
            </div>
        </nav>
        <div class="container mt-5">
            <router-view></router-view>
        </div>
    </main>
</template>
 
<script>
    export default {}
</script>

ਫਿਰ, ਖੋਲ੍ਹੋ resource / js / components / category / List.vue  ਅਤੇ ਫਾਈਲ ਵਿੱਚ ਹੇਠਾਂ ਦਿੱਤੇ ਕੋਡ ਨੂੰ ਸ਼ਾਮਲ ਕਰੋ:

<template>
    <div class="row">
        <div class="col-12 mb-2 text-end">
            <router-link :to='{name:"categoryAdd"}' class="btn btn-primary">Create</router-link>
        </div>
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h4>Category</h4>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Title</th>
                                    <th>Description</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                            <tbody v-if="categories.length > 0">
                                <tr v-for="(category,key) in categories" :key="key">
                                    <td>{{ category.id }}</td>
                                    <td>{{ category.title }}</td>
                                    <td>{{ category.description }}</td>
                                    <td>
                                        <router-link :to='{name:"categoryEdit",params:{id:category.id}}' class="btn btn-success">Edit</router-link>
                                        <button type="button" @click="deleteCategory(category.id)" class="btn btn-danger">Delete</button>
                                    </td>
                                </tr>
                            </tbody>
                            <tbody v-else>
                                <tr>
                                    <td colspan="4" align="center">No Categories Found.</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name:"categories",
    data(){
        return {
            categories:[]
        }
    },
    mounted(){
        this.getCategories()
    },
    methods:{
        async getCategories(){
            await this.axios.get('/api/category').then(response=>{
                this.categories = response.data
            }).catch(error=>{
                console.log(error)
                this.categories = []
            })
        },
        deleteCategory(id){
            if(confirm("Are you sure to delete this category ?")){
                this.axios.delete(`/api/category/${id}`).then(response=>{
                    this.getCategories()
                }).catch(error=>{
                    console.log(error)
                })
            }
        }
    }
}
</script>

ਉਸ ਤੋਂ ਬਾਅਦ, ਖੋਲ੍ਹੋ  resource /js/components/category/Add.vue  ਅਤੇ ਫਾਈਲ ਵਿੱਚ ਹੇਠਾਂ ਦਿੱਤੇ ਕੋਡ ਨੂੰ ਅਪਡੇਟ ਕਰੋ:

<template>
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h4>Add Category</h4>
                </div>
                <div class="card-body">
                    <form @submit.prevent="create">
                        <div class="row">
                            <div class="col-12 mb-2">
                                <div class="form-group">
                                    <label>Title</label>
                                    <input type="text" class="form-control" v-model="category.title">
                                </div>
                            </div>
                            <div class="col-12 mb-2">
                                <div class="form-group">
                                    <label>Description</label>
                                    <input type="text" class="form-control" v-model="category.description">
                                </div>
                            </div>
                            <div class="col-12">
                                <button type="submit" class="btn btn-primary">Save</button>
                            </div>
                        </div>                        
                    </form>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name:"add-category",
    data(){
        return {
            category:{
                title:"",
                description:""
            }
        }
    },
    methods:{
        async create(){
            await this.axios.post('/api/category',this.category).then(response=>{
                this.$router.push({name:"categoryList"})
            }).catch(error=>{
                console.log(error)
            })
        }
    }
}
</script>

ਉਸ ਤੋਂ ਬਾਅਦ, ਖੋਲ੍ਹੋ  resource /js/components/category/Edit.vue  ਅਤੇ ਫਾਈਲ ਵਿੱਚ ਹੇਠਾਂ ਦਿੱਤੇ ਕੋਡ ਨੂੰ ਅਪਡੇਟ ਕਰੋ:


<template>
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h4>Update Category</h4>
                </div>
                <div class="card-body">
                    <form @submit.prevent="update">
                        <div class="row">
                            <div class="col-12 mb-2">
                                <div class="form-group">
                                    <label>Title</label>
                                    <input type="text" class="form-control" v-model="category.title">
                                </div>
                            </div>
                            <div class="col-12 mb-2">
                                <div class="form-group">
                                    <label>Description</label>
                                    <input type="text" class="form-control" v-model="category.description">
                                </div>
                            </div>
                            <div class="col-12">
                                <button type="submit" class="btn btn-primary">Update</button>
                            </div>
                        </div>                        
                    </form>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name:"update-category",
    data(){
        return {
            category:{
                title:"",
                description:"",
                _method:"patch"
            }
        }
    },
    mounted(){
        this.showCategory()
    },
    methods:{
        async showCategory(){
            await this.axios.get(`/api/category/${this.$route.params.id}`).then(response=>{
                const { title, description } = response.data
                this.category.title = title
                this.category.description = description
            }).catch(error=>{
                console.log(error)
            })
        },
        async update(){
            await this.axios.post(`/api/category/${this.$route.params.id}`,this.category).then(response=>{
                this.$router.push({name:"categoryList"})
            }).catch(error=>{
                console.log(error)
            })
        }
    }
}
</script>

DefiVue ਰਾਊਟਰ ਵਿੱਚ CRUD ਐਪ ਦਾ ਮਾਰਗ ਪੂਰਾ ਕਰੋ

ਹੁਣ, ਤੁਹਾਨੂੰ ਕਰਨਾ ਪਵੇਗਾ defiਨੂੰ ਖਤਮ Vue routes, ਅਤੇ ਅਜਿਹਾ ਕਰਨ ਲਈ ਫੋਲਡਰ 'ਤੇ ਜਾਓ  resource / js , ਫਾਈਲ ਬਣਾਓ route.js  ਅਤੇ ਫਾਈਲ ਵਿੱਚ ਹੇਠਾਂ ਦਿੱਤੇ ਕੋਡ ਨੂੰ ਅਪਡੇਟ ਕਰੋ:

const Welcome = () => import('./components/Welcome.vue' /* webpackChunkName: "resource/js/components/welcome" */)
const CategoryList = () => import('./components/category/List.vue' /* webpackChunkName: "resource/js/components/category/list" */)
const CategoryCreate = () => import('./components/category/Add.vue' /* webpackChunkName: "resource/js/components/category/add" */)
const CategoryEdit = () => import('./components/category/Edit.vue' /* webpackChunkName: "resource/js/components/category/edit" */)

export const routes = [
    {
        name: 'home',
        path: '/',
        component: Welcome
    },
    {
        name: 'categoryList',
        path: '/category',
        component: CategoryList
    },
    {
        name: 'categoryEdit',
        path: '/category/:id/edit',
        component: CategoryEdit
    },
    {
        name: 'categoryAdd',
        path: '/category/add',
        component: CategoryCreate
    }
]

ਇੱਥੇ ਅਸੀਂ ਕੰਪੋਨੈਂਟਸ ਦੀ ਵਰਤੋਂ ਕੀਤੀ ਹੈ ਹੌਲੀ ਲੋਡਿੰਗਵਯੂ ਜੇਐਸ ਇੱਕ ਤਰੀਕੇ ਨਾਲ ਭਾਗਾਂ ਦੀ ਲੋਡਿੰਗ ਦਾ ਪ੍ਰਬੰਧਨ ਕਰਦਾ ਹੈ lazy ਮਾਰਗਾਂ ਦੇ ਨਾਲ, ਇਸ ਲਈ DOM 'ਤੇ ਤੁਸੀਂ ਕੰਪੋਨੈਂਟਾਂ ਨੂੰ ਸਿਰਫ਼ ਉਦੋਂ ਹੀ ਲੋਡ ਕਰ ਸਕਦੇ ਹੋ ਜਦੋਂ ਉਹਨਾਂ ਨੂੰ ਮਾਰਗਾਂ ਰਾਹੀਂ ਲੋੜ ਹੁੰਦੀ ਹੈ।

app.js ਵਿੱਚ Vue.js ਨਿਰਭਰਤਾ ਸ਼ਾਮਲ ਕਰੋ

ਹੁਣ ਤੁਹਾਨੂੰ ਸਾਰੇ ਮਾਰਗ, vue-axios ਅਤੇ ਹੋਰ ਨਿਰਭਰਤਾਵਾਂ ਨੂੰ ਜੋੜਨ ਦੀ ਲੋੜ ਹੈ।

resource / js / app.js

require('./bootstrap');
import vue from 'vue'
window.Vue = vue;

import App from './components/App.vue';
import VueRouter from 'vue-router';
import VueAxios from 'vue-axios';
import axios from 'axios';
import {routes} from './routes';
 
Vue.use(VueRouter);
Vue.use(VueAxios, axios);
 
const router = new VueRouter({
    mode: 'history',
    routes: routes
});
 
const app = new Vue({
    el: '#app',
    router: router,
    render: h => h(App),
});

webpack.mix.js ਨੂੰ ਅੱਪਡੇਟ ਕਰੋ

webpack.mix.js

const mix = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel applications. By default, we are compiling the CSS
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/js/app.js', 'public/js')
    .postCss('resources/css/app.css', 'public/css', [
        //
    ]).vue();

ਵਿਕਾਸ ਸਰਵਰ ਚਲਾਓ

ਟਰਮੀਨਲ ਖੋਲ੍ਹੋ ਅਤੇ ਇਹ ਕਮਾਂਡ ਚਲਾਓ:

npm run watch
php artisan serve

ਅਪਰਿ ਲੋਕਲਹੋਸਟ: 8000 ਬਰਾਊਜ਼ਰ ਵਿੱਚ.

BlogInnovazione.it

ਇਨੋਵੇਸ਼ਨ ਨਿਊਜ਼ਲੈਟਰ
ਨਵੀਨਤਾ ਬਾਰੇ ਸਭ ਤੋਂ ਮਹੱਤਵਪੂਰਨ ਖ਼ਬਰਾਂ ਨੂੰ ਨਾ ਭੁੱਲੋ। ਉਹਨਾਂ ਨੂੰ ਈਮੇਲ ਦੁਆਰਾ ਪ੍ਰਾਪਤ ਕਰਨ ਲਈ ਸਾਈਨ ਅੱਪ ਕਰੋ।

ਤਾਜ਼ਾ ਲੇਖ

ਕੈਟਾਨੀਆ ਪੌਲੀਕਲੀਨਿਕ ਵਿਖੇ ਐਪਲ ਦਰਸ਼ਕ ਦੇ ਨਾਲ, ਔਗਮੈਂਟੇਡ ਰਿਐਲਿਟੀ ਵਿੱਚ ਨਵੀਨਤਾਕਾਰੀ ਦਖਲ

ਐਪਲ ਵਿਜ਼ਨ ਪ੍ਰੋ ਕਮਰਸ਼ੀਅਲ ਵਿਊਅਰ ਦੀ ਵਰਤੋਂ ਕਰਦੇ ਹੋਏ ਇੱਕ ਓਫਥਲਮੋਪਲਾਸਟੀ ਓਪਰੇਸ਼ਨ ਕੈਟਾਨੀਆ ਪੌਲੀਕਲੀਨਿਕ ਵਿਖੇ ਕੀਤਾ ਗਿਆ ਸੀ...

3 ਮਈ 2024

ਬੱਚਿਆਂ ਲਈ ਰੰਗਦਾਰ ਪੰਨਿਆਂ ਦੇ ਲਾਭ - ਹਰ ਉਮਰ ਲਈ ਜਾਦੂ ਦੀ ਦੁਨੀਆ

ਰੰਗਾਂ ਰਾਹੀਂ ਵਧੀਆ ਮੋਟਰ ਹੁਨਰਾਂ ਦਾ ਵਿਕਾਸ ਕਰਨਾ ਬੱਚਿਆਂ ਨੂੰ ਲਿਖਣ ਵਰਗੇ ਹੋਰ ਗੁੰਝਲਦਾਰ ਹੁਨਰਾਂ ਲਈ ਤਿਆਰ ਕਰਦਾ ਹੈ। ਰੰਗ ਕਰਨ ਲਈ…

2 ਮਈ 2024

ਭਵਿੱਖ ਇੱਥੇ ਹੈ: ਸ਼ਿਪਿੰਗ ਉਦਯੋਗ ਗਲੋਬਲ ਆਰਥਿਕਤਾ ਵਿੱਚ ਕਿਵੇਂ ਕ੍ਰਾਂਤੀ ਲਿਆ ਰਿਹਾ ਹੈ

ਜਲ ਸੈਨਾ ਖੇਤਰ ਇੱਕ ਸੱਚੀ ਗਲੋਬਲ ਆਰਥਿਕ ਸ਼ਕਤੀ ਹੈ, ਜਿਸ ਨੇ 150 ਬਿਲੀਅਨ ਮਾਰਕੀਟ ਵੱਲ ਨੈਵੀਗੇਟ ਕੀਤਾ ਹੈ...

1 ਮਈ 2024

ਪ੍ਰਕਾਸ਼ਕ ਅਤੇ ਓਪਨਏਆਈ ਆਰਟੀਫੀਸ਼ੀਅਲ ਇੰਟੈਲੀਜੈਂਸ ਦੁਆਰਾ ਸੰਸਾਧਿਤ ਜਾਣਕਾਰੀ ਦੇ ਪ੍ਰਵਾਹ ਨੂੰ ਨਿਯਮਤ ਕਰਨ ਲਈ ਸਮਝੌਤਿਆਂ 'ਤੇ ਹਸਤਾਖਰ ਕਰਦੇ ਹਨ

ਪਿਛਲੇ ਸੋਮਵਾਰ, ਫਾਈਨੈਂਸ਼ੀਅਲ ਟਾਈਮਜ਼ ਨੇ ਓਪਨਏਆਈ ਨਾਲ ਇੱਕ ਸੌਦੇ ਦਾ ਐਲਾਨ ਕੀਤਾ। FT ਆਪਣੀ ਵਿਸ਼ਵ ਪੱਧਰੀ ਪੱਤਰਕਾਰੀ ਨੂੰ ਲਾਇਸੰਸ ਦਿੰਦਾ ਹੈ...

30 ਅਪ੍ਰੈਲ 2024

ਆਪਣੀ ਭਾਸ਼ਾ ਵਿੱਚ ਇਨੋਵੇਸ਼ਨ ਪੜ੍ਹੋ

ਇਨੋਵੇਸ਼ਨ ਨਿਊਜ਼ਲੈਟਰ
ਨਵੀਨਤਾ ਬਾਰੇ ਸਭ ਤੋਂ ਮਹੱਤਵਪੂਰਨ ਖ਼ਬਰਾਂ ਨੂੰ ਨਾ ਭੁੱਲੋ। ਉਹਨਾਂ ਨੂੰ ਈਮੇਲ ਦੁਆਰਾ ਪ੍ਰਾਪਤ ਕਰਨ ਲਈ ਸਾਈਨ ਅੱਪ ਕਰੋ।

ਸਾਡੇ ਨਾਲ ਪਾਲਣਾ