【问题标题】:issue with redirecting with livewire component使用 livewire 组件重定向的问题
【发布时间】:2021-02-11 18:04:00
【问题描述】:

我正在使用带有 livewire 的 laravel-8,我在其中创建了服务模块,我想在单击 create 按钮时重定向到另一个页面,因为我在下面的代码中创建了

<button wire:click="create()" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded my-3">Create New Service</button>
//with route

use App\Http\Livewire\Service\Service;
Route::get('service', Service::class);


public function render()
{
    $this->service = ServiceModel::all();
    return view('livewire.service.service');
}


public function create()
{
    $this->category = CategoryModel::all();
    return view('livewire.service.create');
}

但它不在该页面上重定向

有人可以帮我吗

【问题讨论】:

    标签: laravel-8 laravel-livewire


    【解决方案1】:

    如果你按名称调用方法,但没有函数调用,它应该可以工作:

    <button wire:click="create"
    

    【讨论】:

      【解决方案2】:

      在create()方法中,你必须在创建服务后返回redirect()->route('route name'),

      它也可以这样工作:

      return redirect()->to('service');
      

      【讨论】:

        猜你喜欢
        • 2021-09-28
        • 2011-02-07
        • 1970-01-01
        • 1970-01-01
        • 2017-11-22
        • 2010-12-29
        • 2011-11-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多