VueQuill Documentation

website·Indexed 29 days ago

https://vueup.github.io/vue-quill/

A Vue 3 component wrapper for the Quill rich text editor. It supports server-side rendering (SSR), including Nuxt integration with SWR, ISR, and prerendered routes. Features include customizable toolbars, themes (snow and bubble), and support for Delta content via v-model:content.

Tokens
4.5K
Snippets
31
Records
41
Agent score
75%

What's inside VueQuill

  1. Overview of VueQuill

    VueQuill is a Vue 3 component used for building rich text editors, powered by the Quill editor library. Note that VueQuill is currently in @beta version; it is not yet recommended for critical production use as some features are not finalized and may undergo breaking changes.
  2. Implement a Delta editor with SSR in Nuxt

    In a Nuxt application, a Delta editor can be initialized using Delta content. The editor is designed to be hydrated on the client side after the Nuxt page has been delivered from the server, ensuring that the rich text content is correctly rendered and interactive.
  3. Register VueQuill globally in a Vue 3 app instance

    To use the Quill editor globally across a Vue 3 application, register the QuillEditor component with the app instance. This is applicable for both standard browser scripts and Single File Component (SFC) setups.
    import { createApp } from 'vue'
    import { QuillEditor } from '@vueup/vue-quill'
    import '@vueup/vue-quill/dist/vue-quill.snow.css'
    import App from './App.vue'
    
    const app = createApp(App)
    app.component('QuillEditor', QuillEditor)
    app.mount('#app')
  4. Install VueQuill via CDN

    VueQuill is available as a UMD module for browser use. To use it via CDN, you must load Vue.js, the VueQuill JavaScript library, and the VueQuill CSS theme. Once loaded, the component is accessible through the VueQuill.QuillEditor global variable. For production environments, it is recommended to link to a specific version number rather than @latest to prevent unexpected breakages.
    <!-- include VueJS first -->
    <script src="https://unpkg.com/vue@3"></script>
    
    <!-- use the latest VueQuill release -->
    <script src="https://unpkg.com/@vueup/vue-quill@latest"></script>
    <link rel="stylesheet" href="https://unpkg.com/@vueup/vue-quill@latest/dist/vue-quill.snow.prod.css">
    
    <!-- OR point to a specific VueQuill release -->
    <script src="https://unpkg.com/@vueup/vue-quill@version"></script>
    <link rel="stylesheet" href="https://unpkg.com/@vueup/vue-quill@version/dist/vue-quill.snow.prod.css">
  5. Register custom Formats and Blots in VueQuill

    When a package requires formats or blots to be registered before the module itself, use a full registration path in the name field.

    • Use the prefix blots/ to register a Quill blot. These are not added to the module options.
    • Use the prefix modules/ to register a Quill module. Its options will be passed to Quill as modules.{name}.

    If you are using the formats option in your editor configuration, ensure you include the name of the custom blot to allow it to be rendered in the editor contents.

    import { Mention, MentionBlot } from 'quill-mention'
    
    const modules = [
      {
        name: 'blots/mention',
        module: MentionBlot,
      },
      {
        name: 'modules/mention',
        module: Mention,
        options: {
          mentionDenotationChars: ['@'],
          source: (searchTerm, renderList) => {
            renderList([], searchTerm)
          },
        },
      },
    ]
    
    // To allow the blot in the editor contents:
    const options = {
      formats: ['bold', 'italic', 'mention'],
    }
    
  6. Set global options for QuillEditor

    When registering the QuillEditor component globally, you can define globalOptions to provide default settings across all instances of the editor. This is achieved by overriding the default value of the globalOptions prop on the component definition before registration.
    import { createApp } from 'vue'
    import { QuillEditor } from '@vueup/vue-quill'
    
    const app = createApp()
    
    const globalOptions = {
      debug: 'info',
      modules: {
        toolbar: 'minimal'
      },
      placeholder: 'Compose an epic...',
      readOnly: true,
      theme: 'snow'
    }
    
    // Set default globalOptions prop
    QuillEditor.props.globalOptions.default = () => globalOptions
    
    // Register QuillEditor component
    app.component('QuillEditor', QuillEditor)
  7. Register VueQuill locally within a Single File Component

    For local registration within a specific Vue component, import the QuillEditor component and include it in the component's components option. You must also import a CSS theme for the editor to render correctly.
    <script>
    import { QuillEditor } from '@vueup/vue-quill'
    import '@vueup/vue-quill/dist/vue-quill.snow.css'
    
    export default {
      components: {
        QuillEditor
      }
    }
    </script>
    
    <template>
      <QuillEditor theme="snow" />
    </template>
  8. Access the Quill API in an SSR environment

    Because the Quill runtime depends on browser-specific APIs (like document), direct Quill API calls must be executed within browser-only lifecycle hooks. Use the loadQuill function inside onMounted to safely access the Quill instance in an SSR app.
    <script setup>
    import { onMounted } from 'vue'
    import { loadQuill } from '@vueup/vue-quill'
    
    onMounted(async () => {
      const Quill = await loadQuill()
      Quill.register('modules/example', ExampleModule)
    })
    </script>
  9. Install VueQuill via NPM or Yarn

    Install the @vueup/vue-quill package using npm or yarn. This is the recommended installation method when using Vue Single File Components (SFCs).
    npm install @vueup/vue-quill@latest --save
    # OR
    yarn add @vueup/vue-quill@latest
  10. Use VueQuill in Server-Side Rendering (SSR) applications

    VueQuill is compatible with Vue SSR applications. During server-side rendering, the QuillEditor component renders a stable placeholder element and avoids loading the Quill browser runtime. The actual Quill editor is initialized in the browser only after the component has been mounted by Vue.
    <script setup>
    import { ref } from 'vue'
    import { QuillEditor } from '@vueup/vue-quill'
    import '@vueup/vue-quill/dist/vue-quill.snow.css'
    
    const content = ref('<p>Hydrated in the browser.</p>')
    </script>
    
    <template>
      <QuillEditor
        v-model:content="content"
        content-type="html"
        theme="snow"
        toolbar="minimal"
      />
    </template>
  11. Implement a custom toolbar container

    To use a custom HTML structure for the toolbar, set the toolbar prop to the CSS selector (e.g., an ID) of your toolbar container. You can place this container inside the #toolbar slot of the QuillEditor component or anywhere else in your template. Use Quill's standard classes (like ql-bold) to map buttons to editor actions.
    <template>
      <!-- Option 1: Using the #toolbar slot -->
      <QuillEditor toolbar="#my-toolbar">
        <template #toolbar>
          <div id="my-toolbar">
            <button class="ql-bold"></button>
            <button class="ql-italic"></button>
            <button id="custom-button">Custom Action</button>
          </div>
        </template>
      </QuillEditor>
    
      <!-- Option 2: Toolbar outside the component -->
      <QuillEditor toolbar="#external-toolbar"></QuillEditor>
      <div id="external-toolbar">
        <button class="ql-bold"></button>
        <button class="ql-italic"></button>
      </div>
    </template>
  12. Reference for QuillEditor configuration options

    The following attributes can be used within the options or globalOptions objects to customize the editor behavior:
    {
      // DOM Element or CSS selector for confining UI elements (e.g. tooltips). Only considers left/right boundaries.
      bounds: document.body, 
    
      // Debugging level. Static method affecting all Quill instances on the page. Default: 'warn'.
      debug: 'warn', 
    
      // Whitelist of allowed formats. See https://quilljs.com/docs/formats/
      formats: [], 
    
      // Collection of modules and their respective options. See https://quilljs.com/docs/modules/
      modules: {},
    
      // Placeholder text shown when editor is empty.
      placeholder: 'Text here', 
    
      // Whether the editor is instantiated in read-only mode. Default: false.
      readOnly: false, 
    
      // DOM Element or CSS selector for the container with scrollbars (overflow-y: auto).
      // Used to fix scroll jumping when Quill auto-grows and an ancestor handles scrolling.
      scrollingContainer: null, 
    
      // Theme name: 'bubble' or 'snow'. Requires corresponding stylesheet to be included manually.
      theme: 'snow' 
    }