HTML editor using Vue.js 2, and Quill.js, an open source editor
npm install vue2-editor> An easy-to-use but yet powerful and customizable rich text editor powered by Quill.js and Vue.js
_You can use Yarn or NPM_
``bash`
npm install vue2-editor
OR
`bash`
yarn add vue2-editor
`javascript
// Basic Use - Covers most scenarios
import { VueEditor } from "vue2-editor";
// Advanced Use - Hook into Quill's API for Custom Functionality
import { VueEditor, Quill } from "vue2-editor";
`
Add vue2-editor/nuxt to modules section of nuxt.config.js
`javascript`
{
modules: ["vue2-editor/nuxt"];
}
To avoid seeing warnings from Vue about a mismatch in content, you'll need to
wrap the VueEditor component with the client-only component Nuxt provides as
shown here:
`html`
| Name | Type | Default | Description |
| --------------------- | ------- | ---------------------------------------------------- | -------------------------------------------------------------------------------------- |
| customModules | Array | - | Declare Quill modules to register | Use a custom toolbar |
| disabled | Boolean | false | Set to true to disable editor |
| editorOptions | Object | - | Offers object for merging into default config (add formats, custom Quill modules, ect) |
| editorToolbar | Array | \\ _Too long for table. See toolbar example below_ | Use a custom toolbar |
| id | String | quill-container | Set the id (necessary if multiple editors in the same view) |
| placeholder | String | - | Placeholder text for the editor |
| useCustomImageHandler | Boolean | false | Handle image uploading instead of using default conversion to Base64 |
| v-model | String | - | Set v-model to the the content or data property you wish to bind it to |
| Name | Parameters | Description |
| ---------------- | ---------------------------- | ----------------------------------------------------------------------------------- |
| blur | quill | Emitted on blur event |focus
| focus | quill | Emitted on event |useCustomImageHandler
| image-added | file, Editor, cursorLocation | Emitted when is true and photo is being added to the editor |useCustomImageHandler
| image-removed | file, Editor, cursorLocation | Emitted when is true and photo has been deleted |selection-change
| selection-change | range, oldRange, source | Emitted on Quill's event |text-change
| text-change | delta, oldDelta, source | Emitted on Quill's event |
`vue
`
If you choose to use the custom image handler, an event is emitted when a a photo is selected.
You can see below that 3 parameters are passed.
1. It passes the file to be handled however you need
2. The Editor instance
3. The cursor position at the time of upload so the image can be inserted at the correct position on success
NOTE In addition to this example, I have created a example repo demonstrating this new feature with an actual server.
`vue
useCustomImageHandler
@image-added="handleImageAdded"
v-model="htmlForEditor"
>
`
`vue
`
`vue
`
`vue
`
`vue
`
`vue
`
There are two ways of using custom modules with Vue2Editor. This is partly because there have been cases in which errors are thrown when importing and attempting to declare custom modules, and partly because I believe it actually separates the concerns nicely.
#### Version 1 - _Import and Register Yourself_
Vue2Editor now exports Quill to assist in this process.
1. When importing VueEditor, also import Quill.
2. Import your custom modules
3. Register the custom modules with Quill
4. Add the necessary configuration to the editorOptions object
`vue
v-model="content">
`
#### Version 2 - _You Import | Vue2Editor Registers_
_(Recommended way)_
1. Import your custom modules
2. Use the customModules prop to declare an array of module(s).editorOptions
3. Add the necessary configuration for those modules in the object under modules as seen below
`vue
:editorOptions="editorSettings"
v-model="content"
>
`
---
Vue2Editor now uses Poi for development
- yarn dev: Run example in development modeyarn docs
- : Development for Docsyarn build
- : Build component in both formatyarn lint`: Run eslint
-
MIT