0

我已经使用 Laravel Breeze 建立了一个项目,并且正在使用其中的一些默认组件。其中之一是在导航栏中使用的下拉组件。默认情况下,您需要单击下拉菜单才能在下方显示菜单。但是,我想修改这个组件,使菜单出现在悬停时,如果您只是单击下拉菜单链接,那么它会将您带到不同的页面。

这是有问题的下拉组件:

@props(['align' => 'right', 'width' => '48', 'contentClasses' => 'py-1 bg-blue-light'])

@php
switch ($align) {
    case 'left':
        $alignmentClasses = 'origin-top-left left-0';
        break;
    case 'top':
        $alignmentClasses = 'origin-top';
        break;
    case 'right':
    default:
        $alignmentClasses = 'origin-top-right right-0';
        break;
}

switch ($width) {
    case '48':
        $width = 'w-48';
        break;
}
@endphp

<div class="relative m-auto" x-data="{ open: false }" @click.away="open = false" @close.stop="open = false">
    <div @click="open = ! open">
        {{ $trigger }}
    </div>

    <div x-show="open"
            x-transition:enter="transition ease-out duration-200"
            x-transition:enter-start="transform opacity-0 scale-95"
            x-transition:enter-end="transform opacity-100 scale-100"
            x-transition:leave="transition ease-in duration-75"
            x-transition:leave-start="transform opacity-100 scale-100"
            x-transition:leave-end="transform opacity-0 scale-95"
            class="absolute z-50 mt-2 {{ $width }} rounded-md shadow-lg {{ $alignmentClasses }}"
            style="display: none;"
            @click="open = false">
        <div class="rounded-md ring-1 ring-black ring-opacity-5 {{ $contentClasses }}">
            {{ $content }}
        </div>
    </div>
</div>

知道如何修改它以使其按照我想要的方式运行吗?

4

1 回答 1

0

当您想要分别打开和关闭菜单时,这可以通过使用Vue JS@mouseover和从 Vue JS 来实现。@mouseleave更新后的代码如下所示:

<div class="relative m-auto" x-data="{ open: false }" @mouseover="open = true" @mouseleave="open = false">
    <div>
        {{ $trigger }}
    </div>

    <div x-show="open"
            x-transition:enter="transition ease-out duration-200"
            x-transition:enter-start="transform opacity-0 scale-95"
            x-transition:enter-end="transform opacity-100 scale-100"
            x-transition:leave="transition ease-in duration-75"
            x-transition:leave-start="transform opacity-100 scale-100"
            x-transition:leave-end="transform opacity-0 scale-95"
            class="absolute z-50 mt-2 {{ $width }} rounded-md shadow-lg {{ $alignmentClasses }}"
            style="display: none;"
            >
        <div class="rounded-md ring-1 ring-black ring-opacity-5 {{ $contentClasses }}">
            {{ $content }}
        </div>
    </div>
</div>
于 2021-09-28T19:59:16.230 回答