vue-contenteditable-directive

v-model isn't compatible with contentdeditable divs - this directive fills in
40,352 15
Install
npm install vue-contenteditable-directive
Latest Version:1.2.0
License:Apache-2.0
Last Updated:Jul 31, 2018
Links: GitHub  ·  npm
Maintainer: asconwe

vue-contenteditable-directive

Vue's built in v-model isn't compatible with contenteditable divs - this directive fills in.

Why use contenteditable divs?

First of all - if you can use a textarea or input with v-model, do that instead. There are a couple of quirks, though, in the implementation of textarea that make contenteditable divs a good fit for certain applications.

  • Editable divs shrink and grow with the text inside of them. Textarea does not.
  • Formatting is generally more extensible in a contenteditable div

Usage

import contenteditableDirective from 'vue-contenteditable-directive'
//...
Vue.use(contenteditableDirective)
<template>
  <div v-contenteditable:message="isEnabled" />
</template>

<script>
export default {
  data() {
    return {
      isEnabled: true,
      message: "hello"
    }
  }
}
</script>

The directive uses innerText to manipulate the DOM by default. However, you can use the modifier, dangerousHTML, to allow the directive to use and set the innerHTML of the editable element:

v-contenteditable:someDataKey.dangerousHTML="true"

Be sure to protect your app against XSS!

Related Packages

vue-contenteditable-input

Contenteditable directive with v-model, auto focus, preventing new line on enter...

6,798
vue3-highlight-text

a vue3 directive of highlight text

84,789
vue-proportion-directive

vue 固定元素比例指令

6,003 10
ardirectives

Ardirectives

811
vue-on-click-outside

vue mixin/directive that does something when you click outside a container

169,297 31

Version History

Version Released License
1.2.0 Apache-2.0
1.1.3 Apache-2.0
1.1.2 Apache-2.0
1.1.1 Apache-2.0
1.1.0 Apache-2.0