Skip to content

Latest commit

 

History

History
76 lines (60 loc) · 1.73 KB

README.md

File metadata and controls

76 lines (60 loc) · 1.73 KB

Nuxt DatoCMS Plugin

NuxtJS plugin that creates a clean and elegant way to fetch data from DatoCMS.

Setup

  1. Add nuxt-datocms module to your project
# Navigate to modules directory of Nuxt project
cd modules

# If modules doesn't exist, create it
mkdir modules && cd modules

# Clone this repo to modules directory
git clone https://github.com/StudioRotate/nuxt-datocms.git
  1. Add required module dependecies
yarn add datocms-listen graphql graphql-requeset
  1. Add nuxt-datocms to the modules section of nuxt.config.js
/// nuxt.config.js
{
  modules: [
    // Simple usage
    ['nuxt-datocms', {
      options: {
        datoToken: <DATO-API-TOKEN> // Add Dato API token
      }
    }]
  ]
}

Or a separate section nuxt-datocms for module options:

// nuxt.config.js
{
  modules: [
    // Simple usage
    'nuxt-datocms',
  ],
  'nuxt-datocms': {
    options: {
      datoToken: <DATO-API-TOKEN> // Add Dato API token
    }
  }
}
  1. Test fetching data from DatoCMS within a page's asyncData lifecycle method.
async asyncData({ $cms }) {
  const data = await $cms.records.fetchRaw(`query {
    _site {
      locales
    }
  }`)
  console.log(data)
}

Documentation

For all configuration, further setup and usage information, please read the parent Plugin Docs.

Development

This module is currently a forked and modified version of @ajshortt/nuxt-datocms. It is recommended that changes be made on an instance-by-instance manner. However, if the changes are very useful to other instances, please submit a PR within the module repo