Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need Help - Searching for a user then full page reloading, not feel like SPA @latest Breeze Scaffold #308

Open
inckmo opened this issue Aug 10, 2023 · 0 comments

Comments

@inckmo
Copy link

inckmo commented Aug 10, 2023

Searching a user then Full reloading page in Vue Inertia

I Just wonder Its not working can someone have a better solution?

`

Laravel v10.18.0
Node v20.5.0 & NPM 9.8.1

Untitled.video.-.Made.with.Clipchamp.1.mp4

Dashboard.vue

<script setup>
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue';
import {Head} from '@inertiajs/vue3';
import {ref, watch} from "vue";
import {Inertia} from "@inertiajs/inertia"

const props = defineProps({
    users: {
        type: Object,
        default: () => ({}),
    },
    filters: {
        type: Object,
    }
})

let search = ref(props.filters.search);

watch(search, value => {
        Inertia.get(
            '/dashboard',
            {search: value},
            {
                preserveState: true,
                preserveScroll: true,
                replace: true
            },
        )
    },
)

</script>

<template>
    <Head title="Dashboard"/>

    <AuthenticatedLayout>
        <template #header>
            <h2 class="font-semibold text-xl text-gray-800 leading-tight">Dashboard</h2>
        </template>

        <div class="py-12">
            <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
                <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                    <div class="p-6 text-gray-900">You're logged in!</div>
                </div>
            </div>
        </div>
        <div class="py-12">
            <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
                <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                    <div class="p-6 text-gray-900">
                        <input
                            v-model="search"
                            type="text"
                            placeholder="Search..."
                            class="block w-full py-2 text-sm pr-5 text-gray-700 bg-white border border-gray-200 rounded-lg md:w-80 placeholder-gray-400/70 pl-11 rtl:pr-11 rtl:pl-5  focus:border-indigo-500  focus:ring-indigo-300 focus:outline-none focus:ring focus:ring-opacity-40"
                        ></div>
                    <div class="p-6 text-gray-900">
                        <div v-for="user in users.data" :key="user.id">
                            {{ user.id }}. {{ user.name }}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </AuthenticatedLayout>
</template>

DashboardController.php

<?php

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Http\Request;
use Inertia\Inertia;

class DashboardController extends Controller
{
    public function __invoke(Request $request): \Inertia\Response
    {
        $name = $request->string('search');

        return Inertia::render('Dashboard', [
            'users' => User::query()
                ->when($name, function ($query, $name) {
                    $query->where('name', 'like', "%{$name}%");
                })
                ->paginate(10)
                ->withQueryString()
                ->through(fn ($user) => [
                    'id' => $user->id,
                    'name' => $user->name,
                ]),
            'filters' => $request->only(['search']),
        ]);
    }
}

Screenshot

Controller

If I delete the Build Directory inside public Directory and I got error this Resolve component error when I search

build

Error this Resolve Component is not a function, (page not reload or refresh)

dashboardcopy

Build
resolvecomponent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant