0.2.0 • Published 3 years ago

nuxt-algolia v0.2.0

Weekly downloads
9
License
MIT
Repository
github
Last release
3 years ago

nuxt-algolia

npm version npm downloads Github Actions CI Codecov License

Simple wrapper/integration for Algolia InstantSearch.

📖 Release Notes

Setup

  1. Add nuxt-algolia dependency to your project
yarn add nuxt-algolia # or npm install nuxt-algolia
  1. Add nuxt-algolia to the modules section of nuxt.config.js
{
  modules: [
    'nuxt-algolia'
  ],

  publicRuntimeConfig: {
    algolia: {
      applicationId: [YOUR APPLICATION ID],
      apiKey: [YOUR API KEY],
    }
  }
}

Usage

Component

asyncData

async asyncData ({ $algolia }) {
  const index = $algolia.initIndex('instant_search');
  const results = await index.search('Google');
  return results;
}

methods/created/mounted/etc

methods: {
  async fetchResults(query) {
    const index = this.$algolia.initIndex('instant_search');
    this.results = await index.search(query);
  }
}

Store actions (including nuxtServerInit)

// In store
{
  actions: {
    async fetchGoogleProducts ({ commit }) {
      const index = this.$algolia.initIndex('instant_search');
      const products = await index.search('Google');
      commit('SET_PRODUCTS', products);
    }
  }
}

Development

  1. Clone this repository
  2. Install dependencies using yarn install
  3. Start development server using yarn dev

License

MIT License