Integrate CKEditor 5 with Nuxt using CDN
Nuxt is a Vue.js meta-framework for creating full-stack web applications. It offers everything you would expect from a modern framework, including various rendering modes, file-based routing, automatic code splitting, a large ecosystem of plugins and hosting integrations, and more.
CKEditor 5 does not support server-side rendering, but you can integrate it with the Nuxt framework. In this guide, you will add the editor to a Nuxt project. For this purpose, you will need a Nuxt project and the official CKEditor 5 Vue component.
CKEditor 5 Builder
In our interactive Builder you can quickly get a taste of CKEditor 5. It offers an easy-to-use user interface to help you configure, preview, and download the editor suited to your needs. You can easily select:
- The editor type.
- The features you need.
- Preferred framework (React, Angular, Vue or Vanilla JS).
- Preferred distribution method.
At the end you get ready-to-use code tailored to your needs!
# Setting up the project
This guide assumes you already have a Nuxt project. To create such a project, follow the Nuxt installation guide.
# Using from CDN
To use our Cloud CDN services, create a free account. Learn more about license key activation.
Nuxt is based on Vue.js, so install the CKEditor 5 WYSIWYG editor component for Vue.js, too:
npm install @ckeditor/ckeditor5-vue
You will use the installed dependencies in a Vue.js component. Create a new component in the components
directory, for example, components/Editor.vue
. It will use the <ckeditor>
component to run the editor. The following example shows a single file component with open-source and premium CKEditor 5 plugins.
<template>
<ckeditor
v-if="editor"
v-model="data"
:editor="editor"
:config="config"
/>
</template>
<script setup>
import { ref, computed } from 'vue';
import { Ckeditor, useCKEditorCloud } from '@ckeditor/ckeditor5-vue';
const cloud = useCKEditorCloud( {
version: '44.3.0',
premium: true
} );
const data = ref( '<p>Hello world!</p>' );
const editor = computed( () => {
if ( !cloud.data.value ) {
return null;
}
return cloud.data.value.CKEditor.ClassicEditor;
} );
const config = computed( () => {
if ( !cloud.data.value ) {
return null;
}
const { Essentials, Paragraph, Bold, Italic } = cloud.data.value.CKEditor;
const { FormatPainter } = cloud.data.value.CKEditorPremiumFeatures;
return {
licenseKey: '<YOUR_LICENSE_KEY>',
plugins: [ Essentials, Paragraph, Bold, Italic, FormatPainter ],
toolbar: [ 'undo', 'redo', '|', 'bold', 'italic', '|', 'formatPainter' ]
};
} );
</script>
In the above example, the useCKEditorCloud
hook loads the editor code and plugins from CDN. To use premium plugins, set the premium
property to true
and provide your license key in the configuration. For more information about the useCKEditorCloud
helper, see the Loading CDN resources guide.
Now, you can import and use the Editor.vue
component anywhere in your application.
<template>
<ClientOnly>
<Editor />
</ClientOnly>
</template>
Notice that the <Editor>
component is wrapped in a <ClientOnly>
component. It is required because CKEditor 5 does not support server-side rendering. The <ClientOnly>
component ensures that the editor is rendered only on the client side.
You can run your project now using the npm run dev
command to see your application in the browser.
In the example above, we only used basic features of the <ckeditor>
component. To learn more about additional features and configuration options, refer to the Vue.js integration guide.
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.