JSFiddle - React, Tailwind, and code Playground

by Jack Xie

HTML

<script src="https://cdn.jsdelivr.net/vee-validate/2.0.0-beta.18/vee-validate.js"></script>
<script src="https://cdn.jsdelivr.net/vue/2.1.6/vue.min.js"></script>
<div id="app">
   <textarea v-validate data-vv-name="textMax" data-vv-rules="max: 5" v-model="work.description"></textarea>
   <span v-show="errors.has('textMax')">{{ errors.first('textMax') }}</span>
</div>

JavaScript

Vue.use(VeeValidate);

new Vue({
	el: '#app',
  data: function () {
  	return {
    	work: {
      	description: ''
      }
    }
  },
  beforeMount: function () {
  	this.$watch('work.description', function(newVal, oldVal) {
    	console.log('triggered');
                    let result = this.errors.has('textMax');
    	console.log(result);
                    if (result) {
                        this.work.description = this.work.description.substring(0, 5);
                    }
                });
  }
});