Nuxt.js Module for Comfortable Headless CMS
yarn add comfortable-nuxt
npm install comfortable-nuxt
In nuxt.config.js:
module.exports = {
modules: [
'comfortable-nuxt',
],
comfortable: {
apiKey: 'YOUR_TOKEN'
repositoryApiId: 'YOUR_REPO_ID'
// options: {
// useProxy: true,
// proxy: 'https://your-proxy.com/v1'
// }
}
}
...
}
The comfortable-nuxt module is a wrapper for the comfortable-javasctipt SDK.
The documentation with methods and examples for the JavaScript SDK can be found here: https://docs.comfortable.io/sdk/javascript
The nuxt module initializes the SDK automatically and exposes API methods as $cmft
as a Promise.
SDK Methods like filters and sorting are exposed as $Comfortable
.
For the following examples we'll use the await
operator and fetch content for a page, but you can use $cmft
like a regular promise with any component.
export default {
async asyncData(context) {
const options = {
embedAssets: true
};
const documents = await context.$cmft.getDocuments(options);
return {
documents: documents.data,
}
}
}
/**
* With filters:
*/
export default {
async asyncData(context) {
const options = {
embedAssets: true,
filters: new context.$Comfortable.Filter()
.addAnd('slug', 'equal', context.params.slug)
};
const documents = await context.$cmft.getDocuments(options);
return {
documents: documents.data,
}
}
}
export default {
async asyncData(context) {
const options = {
embedAssets: true
};
const documents = await context.$cmft.getCollection('flyingCars', options);
return {
documents: documents.data,
}
}
}
export default {
async asyncData(context) {
const options = {
embedAssets: true
};
const document = await context.$cmft.getDocument('DOCUMENT_ID', options);
return {
document: document.data,
}
}
}
export default {
async asyncData(context) {
const options = {
embedAssets: true
};
const page = await context.$cmft.getAlias('deLorean', options);
return {
page: page.data,
}
}
}
Pull requests are always welcome!
This repository is published under the MIT license.