Days
Hours
Minutes
Seconds
x

Froala Editor v4.1.4 is Here LEARN MORE

Skip to content

vue

Vue JS Froala WYSIWYG Editor

For Vue 3

A newer SDK for Vue 3 is here.

Compatibility

  • v1 later @legacy
    • Vue.js 1.x
  • v2 later
    • Vue.js 2.x

Installation

Install vue-froala-wysiwyg from npm

npm install vue-froala-wysiwyg --save
  

Integration

1. Require and use Froala Editor component inside your application.

main.js file:

...
  
  // Require Froala Editor js file.
  require('froala-editor/js/froala_editor.pkgd.min.js')
  
  // Require Froala Editor css files.
  require('froala-editor/css/froala_editor.pkgd.min.css')
  require('froala-editor/css/froala_style.min.css')
  
  // Import and use Vue Froala lib.
  import VueFroala from 'vue-froala-wysiwyg'
  Vue.use(VueFroala)
  
  ...
  

App.vue file:

<template>
    <div id="app">
      <froala :tag="'textarea'" :config="config" v-model="model"></froala>
    </div>
  </template>
  
  <script>
  import VueFroala from 'vue-froala-wysiwyg';
  
  export default {
    name: 'app',
    data () {
      return {
        config: {
          events: {
            'froalaEditor.initialized': function () {
              console.log('initialized')
            }
          }
        },
        model: 'Edit Your Content Here!'
      }
    }
  }
  </script>
  

2. Make sure you have the right Webpack settings for loading the CSS files.

var webpack = require('webpack')
  var path = require('path')
  
  module.exports = {
    module: {
      loaders: [
  
        // ...
  
        // Css loader.
        {
          test: /\.css$/,
          loader: 'vue-style-loader!css-loader'
        }
  
      ]
    },
    vue: {
      loaders: {
  
        // ...
  
        // Css loader for Webpack 1.x .
        css: 'vue-style-loader!css-loader'
      }
    }
  })
  

Usage


Initialize

// If model is initialized, 'Init text' text child will be overwritten.
  <froala :tag="'textarea'" :config="config" v-model="model">Init text</froala>
  

:tag attr is used to tell on which tag the editor is initialized.

There are special tags: a, button, img, input.


Options

You can pass editor options as component attribute (optional).

:config="config"

You can pass any existing Froala option. Consult the Froala documentation to view the list of all the available options:

config: {
    placeholderText: 'Edit Your Content Here!',
    charCounterCount: false
  }
  

Aditional option is used: * immediateVueModelUpdate: (default: false) This option updates the Vue model as soon as a key is released in the editor. Note that it may affect performances.


Events and Methods

Events can be passed in with the options, with a key events and object where the key is the event name and the value is the callback function.

config: {
    placeholder: "Edit Me",
    events : {
      'froalaEditor.focus' : function(e, editor) {
        console.log(editor.selection.get());
      }
    }
  }
  

Using the editor instance from the arguments of the callback you can call editor methods as described in the method docs.

Froala events are described in the events docs.


Model

The WYSIWYG HTML editor content model. Two way binding is suported.

v-model="model"

Use the content in other places:

<input v-model="model"/>
  

Special tags

You can also use the editor on img, button, input and a tags:

<froala :tag="img" v-model="imgModel"></froala>
  

The model must be an object containing the attributes for your special tags. Example:

imgModel: {
    src: require('./image.jpg')
  }
  

The model will change as the attributes change during usage.

  • The model can contain a special attribute named innerHTML which inserts innerHTML in the element: If you are using 'button' tag, you can specify the button text like this:
buttonModel: {
    innerHTML: 'Click Me'
  }
  

As the button text is modified by the editor, the innerHTML attribute from buttonModel model will be modified too.

Specific option for special tags

  • vueIgnoreAttrs: (default: null) This option is an array of attributes that you want to ignore when the editor updates the v-model:
config: {
    vueIgnoreAttrs: ['class', 'id']
  }
  

Manual Instantiation

Gets the functionality to operate on the editor: create, destroy and get editor instance. Use it if you want to manually initialize the editor.

:onManualControllerReady="initialize"

initialize: function(initControls) {
    this.initControls = initControls;
    this.deleteAll = () => {
        this.initControls.getEditor().html.set('');
        this.initControls.getEditor().undo.reset();
        this.initControls.getEditor().undo.saveStep();
    };
  }
  

The object received by the function will contain the following methods:

  • initialize: Call this method to initialize the Froala Editor
  • destroy: Call this method to destroy the Froala Editor
  • getEditor: Call this method to retrieve the editor that was created. This method will return null if the editor was not yet created

Displaying HTML

To display content created with the froala editor use the froalaView component.

<froala v-model="content"></froala>
  
  <froalaView v-model="content"></froalaView>
  

Development environment setup

If you want to contribute to vue-froala-wyswiyg, you will first need to install the required tools to get the project going.

Prerequisites

Install dependencies

$ npm install
  

Build

$ npm run build
  

Run Demo

$ npm run dev
  

Do you think we can improve this article? Let us know.

[class^="wpforms-"]
[class^="wpforms-"]
[bws_google_captcha]
<div class="gglcptch gglcptch_v2"><div id="gglcptch_recaptcha_713202383" class="gglcptch_recaptcha"></div> <noscript> <div style="width: 302px;"> <div style="width: 302px; height: 422px; position: relative;"> <div style="width: 302px; height: 422px; position: absolute;"> <iframe src="https://www.google.com/recaptcha/api/fallback?k=6Ld6lNoUAAAAAM626LfCOrnkBFJtYZAKESFCjgv_" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe> </div> </div> <div style="border-style: none; bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px; height: 60px; width: 300px;"> <textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px !important; height: 40px !important; border: 1px solid #c1c1c1 !important; margin: 10px 25px !important; padding: 0px !important; resize: none !important;"></textarea> </div> </div> </noscript></div>
[class^="wpforms-"]
[class^="wpforms-"]
[bws_google_captcha]
<div class="gglcptch gglcptch_v2"><div id="gglcptch_recaptcha_58126697" class="gglcptch_recaptcha"></div> <noscript> <div style="width: 302px;"> <div style="width: 302px; height: 422px; position: relative;"> <div style="width: 302px; height: 422px; position: absolute;"> <iframe src="https://www.google.com/recaptcha/api/fallback?k=6Ld6lNoUAAAAAM626LfCOrnkBFJtYZAKESFCjgv_" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe> </div> </div> <div style="border-style: none; bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px; height: 60px; width: 300px;"> <textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px !important; height: 40px !important; border: 1px solid #c1c1c1 !important; margin: 10px 25px !important; padding: 0px !important; resize: none !important;"></textarea> </div> </div> </noscript></div>
[class^="wpforms-"]
[class^="wpforms-"]
[bws_google_captcha]
<div class="gglcptch gglcptch_v2"><div id="gglcptch_recaptcha_869344586" class="gglcptch_recaptcha"></div> <noscript> <div style="width: 302px;"> <div style="width: 302px; height: 422px; position: relative;"> <div style="width: 302px; height: 422px; position: absolute;"> <iframe src="https://www.google.com/recaptcha/api/fallback?k=6Ld6lNoUAAAAAM626LfCOrnkBFJtYZAKESFCjgv_" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe> </div> </div> <div style="border-style: none; bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px; height: 60px; width: 300px;"> <textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px !important; height: 40px !important; border: 1px solid #c1c1c1 !important; margin: 10px 25px !important; padding: 0px !important; resize: none !important;"></textarea> </div> </div> </noscript></div>