All Projects → hanhdt → Vue Trix

hanhdt / Vue Trix

Licence: mit
Trix text editor component for Vue.js

Projects that are alternatives of or similar to Vue Trix

Vue Codemirror
⌨️ @codemirror component for @vuejs
Stars: ✭ 2,115 (+1230.19%)
Mutual labels:  text-editor, vue-component, vue2
Vue Quill Editor
🍡@quilljs editor component for @vuejs
Stars: ✭ 6,874 (+4223.27%)
Mutual labels:  text-editor, vue-component, vue2
Vue2 Calendar
vue 2.x calendar component
Stars: ✭ 477 (+200%)
Mutual labels:  vue-component, vue2
Vue Star Rating
⭐️ A simple, highly customisable star rating component for Vue 2.x. / 3.x
Stars: ✭ 509 (+220.13%)
Mutual labels:  vue-component, vue2
Vue Typer
Vue component that simulates a user typing, selecting, and erasing text.
Stars: ✭ 691 (+334.59%)
Mutual labels:  vue-component, vue2
Quasar
Quasar Framework - Build high-performance VueJS user interfaces in record time
Stars: ✭ 20,090 (+12535.22%)
Mutual labels:  vue-component, vue2
Vue Video Player
🎞 @videojs component for @vuejs
Stars: ✭ 4,026 (+2432.08%)
Mutual labels:  vue-component, vue2
vue-simple-upload-component
A simple upload component for Vue.js 2.x
Stars: ✭ 14 (-91.19%)
Mutual labels:  vue2, vue-component
Diagram Vue
A editable SVG-based diagram component for Vue
Stars: ✭ 86 (-45.91%)
Mutual labels:  vue-component, vue2
Xcui
🍴 A Vue.js 2.x desktop components colletion
Stars: ✭ 88 (-44.65%)
Mutual labels:  vue-component, vue2
Vue Toastr
Vuejs Toast : Plugin and Component Capability.
Stars: ✭ 93 (-41.51%)
Mutual labels:  vue-component, vue2
Vue Flow Form
Create conversational conditional-logic forms with Vue.js.
Stars: ✭ 315 (+98.11%)
Mutual labels:  vue-component, vue2
vue-icon
Maybe it is the smallest vue component that contains all the feather icons
Stars: ✭ 44 (-72.33%)
Mutual labels:  vue2, vue-component
Vue Touch Ripple
👆 Touch ripple component for @vuejs
Stars: ✭ 443 (+178.62%)
Mutual labels:  vue-component, vue2
vue-notification-bell
Vue.js notification bell component.
Stars: ✭ 64 (-59.75%)
Mutual labels:  vue2, vue-component
Vue Online
A reactive offline indicator component for vue.js
Stars: ✭ 130 (-18.24%)
Mutual labels:  vue-component, vue2
vue-music
基于Laravel5.3+Vue2.0的网易云音乐的SPA应用
Stars: ✭ 85 (-46.54%)
Mutual labels:  vue2, vue-component
v-clappr
👏🏻Vue.js wrapper for Clappr media player
Stars: ✭ 18 (-88.68%)
Mutual labels:  vue2, vue-component
Vue Particles
Vue.js component for particles backgrounds ✨
Stars: ✭ 1,220 (+667.3%)
Mutual labels:  vue-component, vue2
Vue Truncate Collapsed
A simple component that truncates your text and adds a 'Read More/Show Less' clickable.
Stars: ✭ 98 (-38.36%)
Mutual labels:  vue-component, vue2

Vue-Trix Text Editor

npm Build status npm

Simple and lightweight Trix rich-text editor Vue.js component for writing daily

Table of Contents

Getting started

Demo page

vue-trix editor

Integrate into the form

vue-trix in production

Features

  • A simple and lightweight rich-text editor for writing daily.
  • Two-ways binding with v-model easily.
  • Auto-save editor data temporally what you has typed into the form input in case something goes wrong (for example, the browser could crash or you could accidentally refresh the page without submit saving).

Installation

NPM

  $npm install --save vue-trix

YARN

  $yarn add vue-trix

Or directly from latest Github repo

  $npm install --save hanhdt/vue-trix

Mount

Mount with global

in the main.js, import the package as a global component.

import "vue-trix";

Mount with component

import VueTrix from "vue-trix";

export default {
  // ...
  components: {
    VueTrix
  }
};

Setup with Nuxt.js (SSR)

Create mounting plugin file

// plugins/vue_trix.js
import Vue from "vue";
import VueTrix from "vue-trix";

Vue.use(VueTrix);

Update Nuxt.js config file

// nuxt.config.js
plugins: [{ src: "~/plugins/vue_trix", mode: "client" }];

Component Usages

Create a simple editor in your single component file

Add VueTrix component into *.vue template

  <template>
    <!-- ... -->
    <VueTrix v-model="editorContent" placeholder="Enter content" localStorage/>
    <!-- ... -->
  </template>

Integrating with Forms

  <form ...>
    <VueTrix inputId="editor1" v-model="editorContent" placeholder="enter your content..."/>
  </form>

Props descriptions

  • inputId: This is referenced id of the hidden input field defined, it is optional.
  • inputName: This is referenced name of the hidden input field defined, default value is content.
  • placeholder: The placeholder option attribute specifies a short hint that describes the expected value of a editor.
  • autofocus: Automatically focus the editor when it loads
  • disabledEditor: This prop will put the editor in read-only mode.
  • localStorage: The boolean attribute allows saving editor state into browser's localStorage (optional, default is false).

Populating editor content

Init loading content into the editor

In case, you want to load initial data from database then display into the editor. you can use v-model directive with local component's state.

// Declare local component's state is loaded from database
export default {
  // ...
  data() {
    return {
      editorContent: "<h1>Editor contents</h1>"
    };
  }
  // ...
};
  // Assign to v-model directive
  <template>
    <!-- ... -->
    <VueTrix v-model="editorContent"/>
    <!-- ... -->
  </template>

Track data changes

The local component's state will be changed reactively when you modified contents inside the trix editor UI. Therefore, you need to watch the local state for updating content back to database

export default {
  // ...
  methods: {
    updateEditorContent(value) {
      // Update new content into the database via state mutations.
    }
  },
  watch: {
    editorContent: {
      handler: "updateEditorContent"
    }
  }
  // ...
};

Binding attachment events

The <VueTrix/> element emits several events which you can use to observe and respond to changes in editor state.

  • @trix-file-accept fires before an attachment is added to the document. If you don’t want to accept dropped or pasted files, call preventDefault() on this event.

  • @trix-attachment-add fires after an attachment is added to the document. You can access the Trix attachment object through the attachment property on the event. If the attachment object has a file property, you should store this file remotely and set the attachment’s URL attribute.

  • @trix-attachment-remove fires when an attachment is removed from the document. You can access the Trix attachment object through the attachment property on the event. You may wish to use this event to clean up remotely stored files.

Process uploading attachment to remote server

Add binding event listener to trix-attachment-add

  <template>
    <!-- ... -->
    <VueTrix @trix-attachment-add="handleAttachmentChanges"/>
    <!-- ... -->
  </template>

In Javascript

  const remoteHost = 'your remote host';

  function handleAttachmentChanges(event) {
    // 1. get file object
    let file = event.attachment.file;

    // 2. upload file to remote server with FormData
    // ...

    // 3. if upload success, set back the attachment's URL attribute
    // @param object data from remote server response data after upload.
    let attributes = {
      url: remoteHost + data.path,
      href: remoteHost + data.path
    };
    event.attachment.setAttributes(attributes);
  }

Trix document

Full documentation

Contributing

If you're interested in contributing to Vue-Trix or share your opinions, please consider to submitting a pull request or post issues. Also, I will try to code-self documentation.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].