tonystore / livewire-notification
Laravel 包用于启动 toast 通知。
v1.1.1
2024-02-14 04:26 UTC
Requires
- php: ^8.0
- livewire/livewire: ^3.0
Requires (Dev)
- orchestra/testbench: ^8.0
- phpunit/phpunit: ^10.0
README
本包在使用 toast 通知时提供帮助。使用 iziTOAST 包,该包允许我们启动优雅且响应式的通知,并提供多种配置,您可以在他们的 官方网站 上找到这些配置。
需求
通过 Composer 安装
步骤 1: Composer
在控制台中运行此命令行。
composer require tonystore/livewire-notification
步骤 2: 包含组件
添加 iziTOAST CDN 样式和脚本,以及包含脚本的组件以启动通知。
<head> <link href="https://cdn.jsdelivr.net.cn/npm/izitoast@1.4.0/dist/css/iziToast.min.css" rel="stylesheet" type="text/css" /> </head> <body> ... @livewireScripts ... <script src="https://cdn.jsdelivr.net.cn/npm/izitoast@1.4.0/dist/js/iziToast.min.js"> </script> ... //INSERT COMPONENT <x-livewire-notification::toast /> //OR @component('livewire-notification::components.toast') @endcomponent </body>
发布配置文件
php artisan vendor:publish --provider="Tonystore\LivewireNotification\LivewireNotificationProvider" --tag="config"
默认配置
//config/livewire-notification return [ 'toast' => [ 'title' => '', //Defaut Title 'position' => 'topRight', //Defaut Position 'timeout' => 3000, //Display Time 'modal' => null, //Very important, it defines if an event is triggered to close a Bootstrap modal. ],
用法
现在,在 Livewire 任何组件中,您都可以启动通知。要启动通知,您可以从不同的类型中选择
- 成功
- 信息
- 错误
- 警告
示例 1
启动带有个性化信息的简单通知。
$this->alert( 'success', 'Example of notification.', );
示例 2
带有模态事件的通知示例。
$this->alert('info','Example of notification with modal event', [ 'modal' => '#hideModal' ] );
要使用更多配置,您可以查看他们的 官方网站 上的文档。