【问题标题】:Hide default message of ais-state-results widget隐藏 ais-state-results 小部件的默认消息
【发布时间】:2019-10-13 10:47:52
【问题描述】:

我正在使用ais-instant-searchais-state-results 来显示我的数据。我将结果隐藏到query.length > 0。它可以工作,但如果我不输入任何搜索字符串,它总是会显示一条消息。下面是我的代码和截图:

<ais-state-results>
            <p slot-scope="{ query, hits }" v-if="!hits.length">
                Not found for: <q>{{ query }}</q>
            </p>
            <template v-else slot-scope="{ query }">
                <ais-hits v-if="query.length > 0">
                    <template slot="item"
                            slot-scope="{ item }"
                    >
                        <h1>
                            <ais-highlight
                                    :hit="item"
                                    attribute="name"
                            />
                        </h1>

                        <ul>
                            <li>{{ item.price }}</li>
                        </ul>

                    </template>
                </ais-hits>
            </template>
        </ais-state-results>

【问题讨论】:

  • 你解决了你的问题吗?
  • 我还没有解决方案:(

标签: algolia instantsearch.js vue-instant-search


【解决方案1】:

小部件&lt;ais-state-results&gt; 包含a fallback content,它在默认插槽为空时呈现(这是您提供的屏幕截图)。一旦应用程序启动,您在示例中编写的两个条件都是错误的。由于插槽内没有呈现任何内容,因此默认设置会启动。当不满足任何条件时,您可以使用空的div 来解决此问题。这是一个例子:

<ais-state-results>
  <template slot-scope="{ query, hits }">
    <!-- First condition -->
    <p v-if="!hits.length">Not found for: <q>{{ query }}</q></p>
    <!-- Second condition -->
    <ais-hits v-else-if="query" />
    <!-- Fallback condition -->
    <div v-else />
  </template>
</ais-state-results>

你可以在CodeSandbox找到一个活生生的例子。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-11
    • 1970-01-01
    • 2017-07-30
    • 1970-01-01
    • 2014-08-04
    • 1970-01-01
    • 2016-10-13
    • 2019-06-25
    相关资源
    最近更新 更多