芝麻web文件管理V1.00
编辑当前文件:/home/digitalh/public_html/vendor/livewire/livewire/docs/component-hooks.md
## Global Component Hooks In cases where you want to add features or behavior to every single component in your application, you can use Livewire "Component Hooks". Component Hooks allow you to define a single class with the ability to hook in to a Livewire component's lifecycle externally (not on the component class itself, and not in a trait). Before we look at an actual example of using them, here's a generic Component Hook class showing every available method you can use inside them: ```php use Livewire\ComponentHook; class MyComponentHook extends ComponentHook { public static function provide() { // Runs once at application boot. // Can be used to register any services you may need. } public function mount($params, $parent) { // Called when a component is "mounted" // // $params: Array of parameters passed into the component // $parent: The parent component object if this is a nested component } public function hydrate($memo) { // Called when a component is "hydrated" // // $memo: An associative array of the "dehydrated" metadata for this component } public function boot() { // Called when the component boots } public function update($property, $path, $value) { // Called before the component updates... return function () { // Called after the component property has updated... }; } public function call($method, $params, $returnEarly) { // Called before a method on the component is called... return function ($returnValue) { // Called after a method is called }; } public function render($view, $data) { // Called after "render" is called but before the Blade has been rendered... return function ($html) { // Called after the component's view has been rendered }; } public function dehydrate($context) { // Called when a component "dehydrates" } public function exception($e, $stopPropagation) { // Called if an exception is thrown within a component... } } ``` You can register a Component Hook from a service provider like your `App\Providers\AppServiceProvider` like so: ```php