Code Monkey home page Code Monkey logo

vue-quill's Introduction

vue-quill

npm version

A vue component wrapping the quill editor

Demo

You can view a basic demo of this component in this CodeSandbox

Installation

npm install --save vue-quill
-or-
yarn add vue-quill

You will also need to include the following css file in your project

<link href="https://cdn.quilljs.com/1.2.6/quill.snow.css" rel="stylesheet">

Vue 1

For Vue 1 components use v0.1.5 or earlier

Usage

Install the vue plugin

import Vue from 'vue'
import VueQuill from 'vue-quill'

Vue.use(VueQuill)

Component

<quill v-model="content"></quill>

You may want to initialize the synced variable as a valid delta object too

data() {
    return {
        content: {
            ops: [],
        },
    }
}

Configuration

<quill v-model="content" :config="config"></quill>

You can also provide a config object as described in http://quilljs.com/docs/configuration/

data() {
    return {
        content: {
            ops: [],
        },
        config: {
            readOnly: true,
            placeholder: 'Compose an epic...',
        },
    }
}

Options

By default, the component outputs the content as a delta object, you can pass in a prop to return raw html

<quill v-model="content" output="html"></quill>

Custom Formats

To add custom formats to the editor, you can pass an array of formats as a prop. The array should be in the following format

formats: [
    {
        name: 'custom',
        options: {
            attribute: 'custom',
        },
    },
],

Custom Keybindings

You can add custom keybindings by passing through an array in the props, the array should be in the following format

keyBindings: [
    {
        key: 's',
        method: function(range) {
            this.$dispatch('save', this.editor, range)
            return false        
        },
    },
]

Events

This quill component emits events when the text or selection changes on the quill editor

<quill v-model="content" @selection-change="selectionChange"></quill>

<script>
methods: {
    selectionChange(editor, range) {
        if (range) {
            if (range.start !== range.end) {
                this.selectedText = editor.getText(range.start, range.end)
                editor.formatText(range, 'custom', 'hello world')
            }
        }
    },
},

vue-quill's People

Contributors

brockreece avatar paul-watkins-croud avatar joebailey26 avatar lucidlemon avatar darkaonline avatar wayneharris avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.