【问题标题】:Rendering livewire component in a loop. (And tailwindcss)在循环中渲染 livewire 组件。 (和tailwindcss)
【发布时间】:2021-08-04 20:25:23
【问题描述】:

我想用 livewire 组件循环每首 $song。一切都好,买造型就这样坏了:

复制步骤

VerificationSection.php

<?php

namespace App\Http\Livewire;

use App\Models\Song;
use Livewire\Component;

class VerificationSection extends Component
{
    public $songs;

    public function mount(){
        $this->songs = Song::where('isVerified', false)->get();
    }

    public function render()
    {
        return view('livewire.verification-section');
    }
}

livewire.verification-section.blade.php

<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
    @each('livewire.dashboard.song', $songs, 'song', 'livewire.dashboard.song-empty')
</div>

livewire.dashboard.song.blade.php

<div class="w-full bg-white rounded-lg shadow-lg dark:bg-gray-800">
    <div class="px-4 py-2">
        <h1 class="text-3xl font-bold text-gray-800 uppercase dark:text-white">{{ $song->title }}</h1>
        <p class="mt-1 text-sm text-gray-600 dark:text-gray-400">{{ $song->created_at->diffForHumans() }}</p>
    </div>
    @if ($song->artist)
        <img class="object-cover w-full h-48 mt-2"
             src="{{ $song->artist->avatar() }}"
             alt="{{ $song->artist->name }}">
    @endif
    <div class="flex items-center justify-center px-4 py-2 bg-gray-900">
        <button
            class="px-2 py-1 text-xs font-semibold text-gray-900 uppercase transition-colors duration-200 transform bg-white rounded hover:bg-gray-200 focus:bg-gray-400 focus:outline-none">
            Zweryfikuj natychmiast
        </button>
    </div>
</div>

【问题讨论】:

    标签: laravel loops foreach tailwind-css laravel-livewire


    【解决方案1】:

    好的,这很容易。标题长度不同,高度不同。

    【讨论】:

      猜你喜欢
      • 2018-08-08
      • 1970-01-01
      • 2021-03-03
      • 2018-07-09
      • 1970-01-01
      • 2021-12-20
      • 2019-01-07
      • 1970-01-01
      • 2020-12-16
      相关资源
      最近更新 更多