【发布时间】:2021-09-05 14:44:29
【问题描述】:
我有一个问题。我有一个显示 Flash 通知的组件。默认设置为显示绿色复选标记,但我还想包含代码,以便我可以向组件发送“类型”和“消息”变量,并能够显示绿色成功消息或红色失败消息。
我该怎么做?
从我的 livewire 组件中我是这样说的:
if($validatedData->fails()){
$this->notify('Failed creation of extensions');
}else{
$this->notify('Successfully Imported '.$importCount.' Extensions');
}
这是我想发送信息的一种方式:
if($validatedData->fails()){
$this->notify('error', 'Failed creation of extensions');
}else{
$this->notify('success', 'Successfully Imported '.$importCount.' Extensions');
}
在我看来,我有一个刀片组件,其代码如下:
<div x-data="{
messages: [],
remove(message) {
this.messages.splice(this.messages.indexOf(message), 1)
},
}"
@notify.window="let message = $event.detail; messages.push(message); setTimeout(() => { remove(message) }, 2500)"
class="fixed inset-0 flex flex-col items-end justify-center px-4 py-6 space-y-4 pointer-events-none sm:p-6 sm:justify-start">
<template x-for="(message, messageIndex) in messages" :key="messageIndex" hidden>
<div x-transition:enter="transform ease-out duration-300 transition"
x-transition:enter-start="translate-y-2 opacity-0 sm:translate-y-0 sm:translate-x-2"
x-transition:enter-end="translate-y-0 opacity-100 sm:translate-x-0"
x-transition:leave="transition ease-in duration-100" x-transition:leave-start="opacity-100"
x-transition:leave-end="opacity-0"
class="w-full max-w-sm bg-white rounded-lg shadow-lg pointer-events-auto">
<div class="overflow-hidden rounded-lg shadow-xs">
<div class="p-4">
<div class="flex items-start">
<div class="flex-shrink-0">
<svg class="w-6 h-6 text-green-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"></path>
</svg>
</div>
<div class="ml-3 w-0 flex-1 pt-0.5">
<p x-text="message" class="text-sm font-medium leading-5 text-gray-900"></p>
</div>
<div class="flex flex-shrink-0 ml-4">
<button @click="remove(message)"
class="inline-flex text-gray-400 transition duration-150 ease-in-out focus:outline-none focus:text-gray-500">
<svg class="w-5 h-5" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd"
d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
clip-rule="evenodd"></path>
</svg>
</button>
</div>
</div>
</div>
</div>
</div>
</template>
</div>
【问题讨论】:
标签: php laravel laravel-livewire