Vue: method is not a function within inline-template component tag

梦想与她 提交于 2019-12-06 00:19:27

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.

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.


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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!