【问题标题】:Laravel 8 Jetstream Livewire Password Confirmation modal not workingLaravel 8 Jetstream Livewire 密码确认模式不起作用
【发布时间】:2021-07-24 02:39:08
【问题描述】:

我是 Livewire 的新手,我正在尝试使用 Jetstream/Livewire/TailwindCSS 在 Laravel 8 中使用模式密码确认。在向用户提供一些敏感信息之前,我想将此作为附加的保护层。根据https://jetstream.laravel.com/2.x/features/password-confirmation.html (#Modal Confirmation Via Livewire) 中的文档,我应该能够创建一个组件,然后在执行其余代码之前调用该操作来请求密码确认。但是,我无法让它工作。
我的组件(\App\Http\Livewire\TestComponent.php):

<?php

namespace App\Http\Livewire;

use Livewire\Component;

class TestComponent extends Component
{
    public function doSomething(){
        $this->ensurePasswordIsConfirmed();
        //do something here to provide sensitive information, but for now:
        dd('hello world');
    }
}

和我的视图文件:

<!-- some other stuff -->
<x-jet-confirms-password wire:then="doSomething">
    <x-jet-button type="button" wire:loading.attr="disabled">
        {{ __('Click Me') }}
    </x-jet-button>
</x-jet-confirms-password>
<!-- rest of page -->

我希望单击按钮并显示密码确认模式,但 UI 上没有任何反应,控制台显示如下错误:

Alpine:无法在 Livewire 组件之外引用“$wire”(在 SupportAlpine.js 中)

Alpine 错误:“TypeError:null 不是对象(正在评估 'wireEl.__livewire')” 表达式:“$wire.startConfirmingPassword('88430b463c8820be758732f8dbb3f7de')” (在 app.js 中)

未处理的承诺拒绝:TypeError:null 不是对象(评估“wireEl.__livewire”)(在 SupportAlpine.js 中)

页面上的其他组件工作正常。我不知道我错过了什么,但我敢肯定它一定是令人尴尬的简单。有任何想法吗?这将不胜感激。提前致谢!

【问题讨论】:

    标签: laravel security laravel-livewire jetstream password-confirmation


    【解决方案1】:

    尝试在班级顶部添加use ConfirmsPasswords;

    use Laravel\Jetstream\ConfirmsPasswords;
        
    class TestComponent extends Component {
            use ConfirmsPasswords;
        
        public function doSomething(){
            // Some Logic
        }
    }
    

    更多信息请查看此链接Jetstream: Customization + Password Confirmation

    【讨论】:

      猜你喜欢
      • 2021-04-07
      • 2016-12-21
      • 2021-02-22
      • 2021-06-15
      • 1970-01-01
      • 2021-06-24
      • 1970-01-01
      • 2021-06-21
      • 1970-01-01
      相关资源
      最近更新 更多