更新时间:2023-10-25 19:44:04
问题是您使用的是 inline template 用于您的 <ais-results>
组件标签,因此该标签内的数据引用范围为 <ais-results>
实例.这意味着 Vue 正在 <ais-results>
组件上寻找 getTemplate
方法,但没有找到.
The issue is that you’re using an inline template for your <ais-results>
component tag, so the data references within that tag are scoped to the <ais-results>
instance. This means Vue is looking for a getTemplate
method on the <ais-results>
component, but not finding it.
在您的情况下,您可以使用 result
数据发出一个事件,然后在 <ais 上侦听该事件,而不是直接调用
标签.getTemplate
-results>
In your case, instead of directly calling getTemplate
, you could emit an event with the result
data and then listen for the event on the <ais-results>
tag.
下面是一个简化的例子,点击内联模板中的 .card
div 将发出 card-click
事件(@click="$emit('card-click', 结果)"
).<ais-results>
标记具有该事件的侦听器 (@card-click="getTemplate"
),因此当 card-click
事件被触发,getTemplate
方法将被调用并自动传递 result
数据.
Below is a simplified example where clicking on the .card
div in the inline template will emit a card-click
event (@click="$emit('card-click', result)"
). The <ais-results>
tag has a listener for that event (@card-click="getTemplate"
), so when the card-click
event is fired, the getTemplate
method will be called with the result
data being passed automatically.
<ais-results :results-per-page="10" inline-template @card-click="getTemplate">
<div class="row">
<div class="col-6" v-for="result in results.slice(0, 5)" :key="result.objectID">
<div class="card" @click="$emit('card-click', result)">
...
</div>
</div>
</div>
</ais-results>