A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.npmjs.com/package/vue-trix below:

vue-trix - npm

Vue-Trix Text Editor

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

Table of Contents Getting started Demo page

Integrate into the form

Features Installation NPM

  $npm install --save vue-trix

YARN 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.

Mount with component

import VueTrix from "vue-trix";

 

export default {

  

  components: {

    VueTrix

  }

};

Setup with Nuxt.js (SSR)

Create mounting plugin file

import Vue from "vue";

import VueTrix from "vue-trix";

 

Vue.use(VueTrix);

Update Nuxt.js config file

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 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.

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

      

    }

  },

  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.

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.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4