lbreda/livewire3-notify

为 Livewire3 简单的通知绑定

v1.0 2024-08-13 12:57 UTC

This package is auto-updated.

Last update: 2024-09-19 09:21:24 UTC


README

Livewire3 Notify 是一个用于 Livewire3SimpleNotify 绑定。就是这样。

安装

您必须安装 SimpleNotify 和这个库

npm i simple-notify
composer require lbreda/livewire3-notify

然后您应该在您的 app.js(或等效文件)中包含 SimpleNotify 脚本

import Notify from 'simple-notify'
import 'simple-notify/dist/simple-notify.css'
window.Notify = Notify

并在您的主布局中包含这个库组件

<html>
<head>
    ...
    @simpleNotify()
</head>
<body>
...

</body>
</html>

使用方法

您可以在 Livewire 应用程序内部简单派发 notify 事件。您可以在负载中设置 Simple Notify 参数(这里是一个参考)。

例如,您可以在组件方法中使用它

#[On('test')]
public function test(): void
{
    $this->dispatch('notify', status: 'error', title: 'Error', text: 'Send halp');
}

或者您可以在视图中使用它

<div>
    <button type="button" wire:click="$dispatch('notify', {status: 'error', title: 'Error', text: 'Send halp'})">Notify</button>
</div>

设置默认配置

您可以通过以下方式导出默认配置

 php artisan vendor:publish --provider 'LBreda\Livewire3Notify\Providers\SimpleNotifyServiceProvider'

您将在您的 config 目录中找到一个 simple-notify.php 文件。按需进行自定义。

编码愉快!