首页 > 解决方案 > Livewire/Blade 组件中的渲染变量

问题描述

我有一个包含多个模态的表,我正在尝试测试在循环中传递行 id 以确保我的模态正常工作。但我无法通过我的 Livewire 组件显示变量的值。

活线组件

<livewire:dashboard.actions :apt_id="$appointments->id"/>

Livewire/dashboard/actions.blade.php

<div><button wire:click="showModal">Show modal</button>

<x-jet-dialog-modal wire:model="showingModal">
    <x-slot name="title">
        {{ __('Delete Account') }}
    </x-slot>
    <x-slot name="content">
        {{ $apt_id }}
    </x-slot>
    <x-slot name="footer">
        <x-jet-secondary-button wire:click="$toggle('showingModal')" wire:loading.attr="disabled">
            {{ __('Nevermind') }}
        </x-jet-secondary-button>

        <x-jet-danger-button class="ml-2" wire:click="deleteUser()" wire:loading.attr="disabled">
            {{ __('Delete Account') }}
        </x-jet-danger-button>
    </x-slot>
</x-jet-dialog-modal></div>

Livewire/仪表板/Actions.php

class Actions extends Component {

public $showingModal = '';
public $apt_id;


public function mount($apt_id)
{
    $this->apt_id = $apt_id;
}

public function showModal()
{
    $this->showingModal = true;
}

public function render()
{

    return view('livewire.dashboard.actions');
}}

标签: phplaravellaravel-bladelaravel-livewire

解决方案


这是因为我需要删除mount()变量并将其更改为 camelCase。


推荐阅读