[英]@click event not triggering alongside element with @blur
I've got a problem when working with VueJS which is kinda getting on my nerfs since I know that it probably relies on something very small but still I'm here trying to get it running for hours.我在使用 VueJS 时遇到了一个问题,这有点让我感到厌烦,因为我知道它可能依赖于非常小的东西,但我仍然在这里试图让它运行几个小时。
I'm using a template which should represent a searchbar with the solutions under it.我正在使用一个模板,它应该代表一个搜索栏,下面有解决方案。 To show the solutions, I'm looping over an object (I'm not done including the filtering of the solutions to that point - wanted to finish this one first).为了展示解决方案,我在 object 上循环(我还没有完成对解决方案的过滤 - 想先完成这个)。 The thing I was trying to do now was filling in the searchbar value with the value I select in the solutions (passing it with a click event).我现在尝试做的事情是在解决方案中用值 I select 填充搜索栏值(通过点击事件传递它)。 But somehow my click event doesn't trigger.但不知何故,我的点击事件没有触发。
I've got the following code-snippet:我有以下代码片段:
<template>
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text">🔍</div>
</div>
<input
type="text"
class="form-control"
@focus="searchFocus = true"
@blur="searchFocus = false"
v-model="searchQuery"
placeholder="Search for vehicles..">
<div class="container p-0">
<div class="dropdown-menu search" v-show="searchFocus">
<a class="dropdown-item bus" href="#"
v-for="vehicle in vehicleObjects"
:key="vehicle.id.key"
v-on:click="setSelectedToQuery(vehicle)">
<span class="ml-4">Bus {{ vehicle.id.name }}
<span class="badge badge-secondary"> {{ vehicle.licenseNumber }}</span>
<span>
</a>
</div>
</div>
</div>
</template>
Am I missing something quite obvious?我错过了一些很明显的东西吗? How can I get the click-event running/triggering?如何让点击事件运行/触发?
Thanks in advance提前致谢
Best Regards此致
There are few things "off" I'll list them by level of impact很少有“关闭”的事情,我将按影响程度列出它们
@blur
fires before click, essentially invalidating @click
@blur
在点击之前触发,本质上使@click
无效<a...>
need to prevent redirect. anchors <a...>
需要防止重定向。 You can use @click.prevent="...
to prevent event propagation, or use another element, since you don't have href
defined anyway.您可以使用@click.prevent="...
来防止事件传播,或使用其他元素,因为您还没有定义href
。span
elements is not closed ( <span>
instead of </span
at the end)您的span
元素之一未关闭(最后是<span>
而不是</span
) To handle @blur
blocking @click
, you could use @mousedown
instead of @click
, since it executes first.要处理@blur
阻塞@click
,您可以使用@mousedown
而不是@click
,因为它首先执行。
Maybe it's the solution: close your last span也许这是解决方案:关闭你的最后一个跨度
Click work for me: https://codesandbox.io/s/morning-browser-fgftf点击为我工作: https://codesandbox.io/s/morning-browser-fgftf
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.