Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A text editor using Vue.js and Quill

License

NotificationsYou must be signed in to change notification settings

davidroyer/vue2-editor

Repository files navigation

An easy-to-use but yet powerful and customizable rich text editor powered by Quill.js and Vue.js

View Docs

Vue2Editor-Centered

📖Release Notes

Install

You can use Yarn or NPM

npm install vue2-editor

OR

yarn add vue2-editor

Usage

// Basic Use - Covers most scenariosimport{VueEditor}from"vue2-editor";// Advanced Use - Hook into Quill's API for Custom Functionalityimport{VueEditor,Quill}from"vue2-editor";

Nuxt.js

Addvue2-editor/nuxt to modules section ofnuxt.config.js

{  modules:["vue2-editor/nuxt"];}

To avoid seeing warnings from Vue about a mismatch in content, you'll need towrap theVueEditor component with theclient-only component Nuxt provides asshown here:

<client-only><VueEditor/></client-only>

Props

NameTypeDefaultDescription
customModulesArray-Declare Quill modules to register
disabledBooleanfalseSet to true to disable editor
editorOptionsObject-Offers object for merging into default config (add formats, custom Quill modules, ect)
editorToolbarArray**Too long for table. See toolbar example belowUse a custom toolbar
idStringquill-containerSet the id (necessary if multiple editors in the same view)
placeholderString-Placeholder text for the editor
useCustomImageHandlerBooleanfalseHandle image uploading instead of using default conversion to Base64
v-modelString-Set v-model to the the content or data property you wish to bind it to

Events

NameParametersDescription
blurquillEmitted onblur event
focusquillEmitted onfocus event
image-addedfile, Editor, cursorLocationEmitted whenuseCustomImageHandler is true and photo is being added to the editor
image-removedfile, Editor, cursorLocationEmitted whenuseCustomImageHandler is true and photo has been deleted
selection-changerange, oldRange, sourceEmitted on Quill'sselection-change event
text-changedelta, oldDelta, sourceEmitted on Quill'stext-change event

Examples

Example - Basic Setup

<template>  <divid="app">    <vue-editorv-model="content"></vue-editor>  </div></template><script>import {VueEditor }from"vue2-editor";exportdefault {  components: {    VueEditor  },data() {return {      content:"<h1>Some initial content</h1>"    };  }};</script>

Example - Custom Image Handler

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 aexample repo demonstrating this new feature with an actual server.

<template>  <divid="app">    <vue-editorid="editor"useCustomImageHandler@image-added="handleImageAdded"v-model="htmlForEditor"    >    </vue-editor>  </div></template><script>import {VueEditor }from"vue2-editor";importaxiosfrom"axios";exportdefault {  components: {    VueEditor  },data() {return {      htmlForEditor:""    };  },  methods: {handleImageAdded:function(file,Editor,cursorLocation,resetUploader) {// An example of using FormData// NOTE: Your key could be different such as:// formData.append('file', file)var formData=newFormData();formData.append("image", file);axios({        url:"https://fakeapi.yoursite.com/images",        method:"POST",        data: formData      })        .then(result=> {consturl=result.data.url;// Get url from responseEditor.insertEmbed(cursorLocation,"image", url);resetUploader();        })        .catch(err=> {console.log(err);        });    }  }};</script>

Example - Set Contents After Page Load

<template>  <divid="app">    <button@click="setEditorContent">Set Editor Contents</button>    <vue-editorv-model="htmlForEditor"></vue-editor>  </div></template><script>import {VueEditor }from"vue2-editor";exportdefault {  components: {    VueEditor  },data() {return {      htmlForEditor:null    };  },  methods: {setEditorContent:function() {this.htmlForEditor="<h1>Html For Editor</h1>";    }  }};</script>

Example - Using Multiple Editors

<template>  <divid="app">    <vue-editorid="editor1"v-model="editor1Content"></vue-editor>    <vue-editorid="editor2"v-model="editor2Content"></vue-editor>  </div></template><script>import {VueEditor }from"vue2-editor";exportdefault {  components: {    VueEditor  },data() {return {      editor1Content:"<h1>Editor 1 Starting Content</h1>",      editor2Content:"<h1>Editor 2 Starting Content</h1>"    };  }};</script><style>#editor1,#editor2 {height:350px;}</style>

Example - Custom Toolbar

<template>  <divid="app">    <vue-editorv-model="content":editorToolbar="customToolbar"></vue-editor>  </div></template><script>import {VueEditor }from"vue2-editor";exportdefault {  components: {    VueEditor  },data() {return {      content:"<h1>Html For Editor</h1>",      customToolbar: [        ["bold","italic","underline"],        [{ list:"ordered" }, { list:"bullet" }],        ["image","code-block"]      ]    };  }};</script>

Example - Saving The Content

<template>  <divid="app">    <button@click="saveContent"></button>    <vue-editorv-model="content"></vue-editor>  </div></template><script>import {VueEditor }from"vue2-editor";exportdefault {  components: {    VueEditor  },data() {return {      content:"<h3>Initial Content</h3>"    };  },  methods: {handleSavingContent:function() {// You have the content to saveconsole.log(this.content);    }  }};</script>

Example - Use a Live Preview

<template>  <divid="app">    <vue-editorv-model="content"></vue-editor>    <divv-html="content"></div>  </div></template><script>import {VueEditor }from'vue2-editor'components: {  VueEditor},exportdefault {data() {return {      content:'<h1>Initial Content</h1>'    }  }}</script>

How To Use Custom Quill Modules

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 theeditorOptions object
<template>  <divid="app">    <vue-editor:editorOptions="editorSettings"v-model="content">  </div></template><script>import {VueEditor,Quill }from'vue2-editor'import {ImageDrop }from'quill-image-drop-module'importImageResizefrom'quill-image-resize-module'Quill.register('modules/imageDrop', ImageDrop)Quill.register('modules/imageResize', ImageResize)exportdefault {    components: {      VueEditor    },data() {return {        content:'<h1>Initial Content</h1>',        editorSettings: {          modules: {            imageDrop:true,            imageResize: {}          }        }      }    }  }</script>

Version 2 -You Import | Vue2Editor Registers

(Recommended way)

  1. Import your custom modules
  2. Use thecustomModules prop to declare an array of module(s).
  3. Add the necessary configuration for those modules in theeditorOptions object under modules as seen below
<template>  <divid="app">    <vue-editor:customModules="customModulesForEditor":editorOptions="editorSettings"v-model="content"    >    </vue-editor>  </div></template><script>import {VueEditor }from"vue2-editor";import {ImageDrop }from"quill-image-drop-module";importImageResizefrom"quill-image-resize-module";exportdefault {  components: {    VueEditor  },data() {return {      content:"<h1>Initial Content</h1>",      customModulesForEditor: [        { alias:"imageDrop", module: ImageDrop },        { alias:"imageResize", module: ImageResize }      ],      editorSettings: {        modules: {          imageDrop:true,          imageResize: {}        }      }    };  }};</script>

Development

Vue2Editor now usesPoi for development

  • yarn dev: Run example in development mode
  • yarn docs: Development for Docs
  • yarn build: Build component in both format
  • yarn lint: Run eslint

License

MIT

About

A text editor using Vue.js and Quill

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors5


[8]ページ先頭

©2009-2025 Movatter.jp