【问题标题】:Livewire component shows its own code but doesn't renderLivewire 组件显示自己的代码但不呈现
【发布时间】:2022-01-23 19:43:41
【问题描述】:

我正在使用 Laravel Jetstream 和 Livewire。我正在尝试根据文档制作自己的 Livewire 组件:

php artisan livewire:make my_component

默认情况下它位于resources/views/livewire/my-component.blade.php。我将此字符串添加到resources/views/profile/show.blade.php 文件:@livewire('my-component')。我想在用户个人资料页面中看到这个组件。

但是我只在页面上看到它的代码而不是组件。

在这张图片中,我添加了我的组件而不是 two-factor-authentication-form.blade.php。这是resources/views/liwevire/my-component.blade.php的代码:

<x-jet-action-section>
    <x-slot name="title">
        {{ __('Two Factor Authentication') }}
    </x-slot>

    <x-slot name="description">
        {{ __('Add additional security to your account using two factor authentication.') }}
    </x-slot>

    <x-slot name="content">
        Some content
    </x-slot>

</x-jet-action-section>

这是resources/views/profile/show.blade.php的一段代码:

@if (Laravel\Fortify\Features::canManageTwoFactorAuthentication())
    <div class="mt-10 sm:mt-0">
        <!-- @livewire('profile.two-factor-authentication-form') -->
        @livewire('my-component')
    </div>
    <x-jet-section-border />
@endif

我该如何解决?

P。 S. 我已经从resources/views/profile/show.blade.php 中删除了评论行,但仍然没有。代码如下:

@if (Laravel\Fortify\Features::canManageTwoFactorAuthentication())
    <div class="mt-10 sm:mt-0">
        @livewire('my-component')
    </div>
    <x-jet-section-border />
@endif

结果:

附言这是app/Http/Livewire/MyComponent的代码:

<?php

namespace App\Http\Livewire;

use Livewire\Component;

class MyComponent extends Component
{
    public function render()
    {
        return view('livewire.my-component');
    }
}

【问题讨论】:

  • 您可以尝试从代码中删除 看看是否有帮助。也许它正在部分注释掉一些内容??
  • @brett 我试过了,但还是没有。
  • 我猜你的路径中的 "liwevire" 是错字?
  • 你可以在你的截图中看到它仍然存在 --> 所以当你注释掉的时候,不要使用 HTML cmets,使用刀片 cmets {{-- this is commented out --}}
  • @brombeer 确定,已修复

标签: php laravel laravel-livewire jetstream


【解决方案1】:

使用 HTML cmets 注释掉刀片渲染组件时要小心,因为它仍然会在 cmets 之间渲染刀片组件

<!-- @livewire('profile.two-factor-authentication-form') -->

使用 {{-- --}}

{{-- @livewire('profile.two-factor-authentication-form') --}}

【讨论】:

  • 它仍然不应该显示任何内容,因为它是 HTML 注释,对吧?
  • @brombeer 除非组件呈现关闭的 html 注释标记,否则它不应该导致它提前取消注释
  • 这似乎没有。而出现在页面上的{{ __('Two Factor Authentication') }} 看起来甚至没有被 Blade 解析
猜你喜欢
  • 2022-12-28
  • 2020-09-11
  • 1970-01-01
  • 1970-01-01
  • 2011-08-08
  • 1970-01-01
  • 2019-04-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多