laravel - 带有 Algolia 和 Laravel 的 Vue-InstantSearch:在空查询中隐藏结果
问题描述
我想弄清楚如何在空搜索查询中隐藏索引/结果。
在我的刀片中,我有代码(从官方文档略有修改):
<ais-instant-search index-name="myIndex" :search-client="searchClient">
<ais-search-box placeholder="Search here"></ais-search-box>
<ais-state-results>
<template slot-scope="{ state: { query } }">
<ais-hits v-if="query.length > 0">
<div slot="item" slot-scope="{ item }">
<h2>@{{ item.Title}}</h2>
<p>@{{ item.Text}}</p>
</div>
</ais-hits>
</template>
</ais-state-results>
</ais-instant-search>
如果我输入搜索查询,这可以正常工作,但在空查询时,这会在我的页面上显示以下不需要的通知(而不是之前不需要的索引):
Use this component to have a different layout based on a certain state.
Fill in the slot, and get access to the following things on the slot-scope:
results: [
"_rawResults",
"hits",
"nbHits",
[..]
如何隐藏此通知?
解决方案
啊,我刚刚找到了我认为的解决方案。如果内部没有 DOM 元素,则会显示此通知文本<ais-hits>
。如果没有查询,则没有,因为“v-if”会删除它。因此,如果我使用“v-show”而不是“v-if”,它可以根据需要工作,因为 DOM 元素仍然存在,但不显示(显示:隐藏)。
<ais-instant-search index-name="myIndex" :search-client="searchClient">
<ais-search-box placeholder="Search here"></ais-search-box>
<ais-state-results>
<template slot-scope="{ state: { query } }">
<ais-hits v-show="query.length > 0">
<div slot="item" slot-scope="{ item }">
<h2>@{{ item.Title}}</h2>
<p>@{{ item.Text}}</p>
</div>
</ais-hits>
</template>
</ais-state-results>
推荐阅读
- python - ImportError: No module named citations
- sql - 在 SQL 中,如何将“ALL”作为 M 和 F 返回
- python - 政权转换多元garch
- kotlin - 不同类中的 CoroutineScope 扩展函数
- c - 为什么 c 库和语言定义 _name 然后 typedef 或 pound 定义 _name 名称?
- sql - SELECT * FROM table 除了聚合函数
- database - 如何在 JaguarDB 中存储空间数据
- java - 如何将 JPanel 放在 JFrame 的前面
- ios - Firebase 值未更新?
- jquery - jQuery $.getJSON 发送字符串