【问题标题】:Render variable in Livewire/Blade componentLivewire/Blade 组件中的渲染变量
【发布时间】:2021-03-03 09:44:40
【问题描述】:

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

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/Dashboard/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');
}}

【问题讨论】:

  • 你确定它传递了你假设的值吗?在您的 mount() 方法中执行 dd($apt_id); 进行检查。

标签: php laravel laravel-blade laravel-livewire


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2021-08-04
    • 2018-09-23
    • 2015-09-13
    • 2020-03-28
    • 2021-04-25
    • 1970-01-01
    • 2021-06-26
    • 2019-06-03
    • 2021-09-15
    相关资源
    最近更新 更多