2.10.3 • Published 3 years ago

vue2-editor v2.10.3

Weekly downloads
37,614
License
MIT
Repository
github
Last release
3 years ago

Vue2Editor

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

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 scenarios
import { VueEditor } from "vue2-editor";

// Advanced Use - Hook into Quill's API for Custom Functionality
import { VueEditor, Quill } from "vue2-editor";

Nuxt.js

Add vue2-editor/nuxt to modules section of nuxt.config.js

{
  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:

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

Props

NameTypeDefaultDescription
customModulesArray-Declare Quill modules to registerUse a custom toolbar
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 on blur event
focusquillEmitted on focus event
image-addedfile, Editor, cursorLocationEmitted when useCustomImageHandler is true and photo is being added to the editor
image-removedfile, Editor, cursorLocationEmitted when useCustomImageHandler is true and photo has been deleted
selection-changerange, oldRange, sourceEmitted on Quill's selection-change event
text-changedelta, oldDelta, sourceEmitted on Quill's text-change event

Examples

Example - Basic Setup

<template>
  <div id="app">
    <vue-editor v-model="content"></vue-editor>
  </div>
</template>

<script>
import { VueEditor } from "vue2-editor";

export default {
  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 a example repo demonstrating this new feature with an actual server.

<template>
  <div id="app">
    <vue-editor
      id="editor"
      useCustomImageHandler
      @image-added="handleImageAdded"
      v-model="htmlForEditor"
    >
    </vue-editor>
  </div>
</template>

<script>
import { VueEditor } from "vue2-editor";
import axios from "axios";
export default {
  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 = new FormData();
      formData.append("image", file);

      axios({
        url: "https://fakeapi.yoursite.com/images",
        method: "POST",
        data: formData
      })
        .then(result => {
          const url = result.data.url; // Get url from response
          Editor.insertEmbed(cursorLocation, "image", url);
          resetUploader();
        })
        .catch(err => {
          console.log(err);
        });
    }
  }
};
</script>

Example - Set Contents After Page Load

<template>
  <div id="app">
    <button @click="setEditorContent">Set Editor Contents</button>
    <vue-editor v-model="htmlForEditor"></vue-editor>
  </div>
</template>

<script>
import { VueEditor } from "vue2-editor";

export default {
  components: {
    VueEditor
  },

  data() {
    return {
      htmlForEditor: null
    };
  },

  methods: {
    setEditorContent: function() {
      this.htmlForEditor = "<h1>Html For Editor</h1>";
    }
  }
};
</script>

Example - Using Multiple Editors

<template>
  <div id="app">
    <vue-editor id="editor1" v-model="editor1Content"></vue-editor>
    <vue-editor id="editor2" v-model="editor2Content"></vue-editor>
  </div>
</template>

<script>
import { VueEditor } from "vue2-editor";

export default {
  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>
  <div id="app">
    <vue-editor v-model="content" :editorToolbar="customToolbar"></vue-editor>
  </div>
</template>

<script>
import { VueEditor } from "vue2-editor";

export default {
  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>
  <div id="app">
    <button @click="saveContent"></button>
    <vue-editor v-model="content"></vue-editor>
  </div>
</template>

<script>
import { VueEditor } from "vue2-editor";

export default {
  components: {
    VueEditor
  },

  data() {
    return {
      content: "<h3>Initial Content</h3>"
    };
  },

  methods: {
    handleSavingContent: function() {
      // You have the content to save
      console.log(this.content);
    }
  }
};
</script>

Example - Use a Live Preview

<template>
  <div id="app">
    <vue-editor v-model="content"></vue-editor>
    <div v-html="content"></div>
  </div>
</template>

<script>
import { VueEditor } from 'vue2-editor'

components: {
  VueEditor
},

export default {
  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 the editorOptions object
<template>
  <div id="app">
    <vue-editor
      :editorOptions="editorSettings"
      v-model="content">
  </div>
</template>

<script>
  import { VueEditor, Quill } from 'vue2-editor'
  import { ImageDrop } from 'quill-image-drop-module'
  import ImageResize from 'quill-image-resize-module'

  Quill.register('modules/imageDrop', ImageDrop)
  Quill.register('modules/imageResize', ImageResize)

  export default {
    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 the customModules prop to declare an array of module(s).
  3. Add the necessary configuration for those modules in the editorOptions object under modules as seen below
<template>
  <div id="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";
import ImageResize from "quill-image-resize-module";

export default {
  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 uses Poi 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

@itnikc/legend-form-makerld-form-makingsocar-vue-libraryfirstbet-admin-frontendrc-ui-designerrc-ui-cmpbillingman-web-customer-componenttestp-cmpapplauncherfavmenuckuessner2applauncherfavmenuckuessner3form-makinghform-makingmform-makingxhform-making-huaform-making-revlko-form-makingdoposoft-form-makelucky-form-makingch-demo-fromlegend-form-maker@hzenfo/form-making-advanced@hzenfo/form-makingmonzemvform-render@myukm/admin-pagerugo-admin@skoda-dms/component-libponentr-libbojuan_com_ponent_lib_raryke_form-makingdcocd-form-makingform-making-advanced-keeponlinevariant-formvariant-form1hotata-vformjl-variant-formmking-form@infinitebrahmanuniverse/nolb-vue2wbu-design-system@everything-registry/sub-chunk-3098variant-form-proemergency-disposaldemo-test-tmier@dpsejahtera/auction-admin-pagedcits-form-makingdemo771diandi-ele-form-quill-editordelibird-common-web-componentdco-create-formfan-formfanstar-formfirebear-web-componentform-builder-betaform-templage-xuform-template-xuform-toastform-wx-makingform-making-yongboform-making-zhanform-making-zhongshaneryuanform-making-zxhform-making-zyform-makingsform-mark-jform-mark-jxtform-mark-testform-mark-zkform-making-modifyingform-making-nortekform-making-nyform-making-scopform-making-secondaryform-making-testform-making-vipform-making-vueform-making-whtform-making-xuform-making-ylform-making-advanced-yl-2021form-making-advanced-yl-2023form-making-advanced_nanbform-making-basicform-making-cusform-making-demoform-making-designerform-making-devform-making-dwform-making-editorform-makingform-making-jiukukuform-making-jtzmdbcform-making-lbform-making-lcform-making-lgdform-making-lhform-making-mform-making-midociform-making-extchartform-making-forkform-making-gener
2.10.3

3 years ago

2.10.3-ssr.4

3 years ago

2.10.3-ssr.5

3 years ago

2.10.3-ssr.2

3 years ago

2.10.3-ssr.3

3 years ago

2.10.3-ssr.1

3 years ago

2.10.3-ssr.0

3 years ago

2.10.1-next.14

5 years ago

2.10.1-next.11

5 years ago

2.10.1-next.10

5 years ago

2.10.1-next.9

5 years ago

2.10.1-next.8

5 years ago

2.10.1-next.7

5 years ago

2.10.1-next.6

5 years ago

2.10.1-next.5

5 years ago

2.10.1-next.1

5 years ago

2.10.1-next.0

5 years ago

2.10.2

5 years ago

2.10.1

5 years ago

2.10.0

5 years ago

2.9.1

5 years ago

2.9.0

5 years ago

2.9.0-next.10

5 years ago

2.9.0-next.9

5 years ago

2.9.0-next.8

5 years ago

2.9.0-next.7

5 years ago

2.9.0-next.6

5 years ago

2.9.0-next.5

5 years ago

2.9.0-next.4

5 years ago

2.9.0-next.2

5 years ago

2.9.0-next.1

5 years ago

2.9.0-next.0

5 years ago

2.8.1

5 years ago

2.8.0-alpha.9

5 years ago

2.8.0-alpha.8

5 years ago

2.8.0-alpha.7

5 years ago

2.8.0-alpha.6

5 years ago

2.8.0-alpha.5

5 years ago

2.8.0-alpha.4

5 years ago

2.8.0-alpha.3

5 years ago

2.8.0-alpha.2

5 years ago

2.8.0-alpha.1

5 years ago

2.7.2

5 years ago

2.7.0-alpha.21

5 years ago

2.7.0-alpha.20

5 years ago

2.7.0-alpha.19

5 years ago

2.7.0-alpha.18

5 years ago

2.7.0-alpha.17

5 years ago

2.7.0-alpha.16

5 years ago

2.7.0-alpha.15

5 years ago

2.7.0-alpha.14

5 years ago

2.7.0-alpha.13

5 years ago

2.7.0-alpha.12

5 years ago

2.7.0-alpha.11

5 years ago

2.7.0-alpha.10

5 years ago

2.7.0-alpha.9

5 years ago

2.7.0-alpha.8

5 years ago

2.7.0-alpha.7

5 years ago

2.7.0-alpha.6

5 years ago

2.7.0-alpha.5

5 years ago

2.7.0-alpha.4

5 years ago

2.7.0-alpha.3

5 years ago

2.7.0-alpha.2

5 years ago

2.7.0-alpha.1

5 years ago

2.7.0-alpha.0

5 years ago

2.6.6

6 years ago

2.6.1

6 years ago

2.6.0

6 years ago

2.5.0

6 years ago

2.4.4

6 years ago

2.4.3

6 years ago

2.4.2

6 years ago

2.4.1

6 years ago

2.3.34

6 years ago

2.3.33

6 years ago

2.3.32

6 years ago

2.3.31

6 years ago

2.3.3

6 years ago

2.3.2

6 years ago

2.3.11

6 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.0.26

7 years ago

2.0.25

7 years ago

2.0.42-images

7 years ago

2.0.41-images

7 years ago

2.0.3-beta

7 years ago

2.0.24

7 years ago

2.0.23

7 years ago

2.0.22

7 years ago

2.0.21

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.2

7 years ago

1.1.12

7 years ago

1.1.11

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.99

7 years ago

1.0.98

7 years ago

1.0.97

7 years ago

1.0.96

7 years ago

1.0.95

7 years ago

1.0.93

7 years ago

1.0.92

7 years ago

1.0.91

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago