Skip to content

Instantly share code, notes, and snippets.

@juanbrujo
Created February 16, 2018 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanbrujo/639cab15e9adfd008e023ea671dbf15f to your computer and use it in GitHub Desktop.
Save juanbrujo/639cab15e9adfd008e023ea671dbf15f to your computer and use it in GitHub Desktop.
VueJS 2 Characters left count && limit
<template>
<div>
<textarea v-model="companyDescription"></textarea>
Add a comment to this line
<p>{{ charactersLeft }}</p>
</div>
</template>
<script>
export default {
data () {
return {
companyDescription: '',
maxDescriptionCharacters: 100
}
},
computed: {
charactersLeft: function () {
let char = this.leWord.length
const limit = this.limit
if (char <= limit) {
return (limit - char) + ' / ' + limit + ' caracteres.'
} else {
this.leWord = this.leWord.substring(0, limit) + '...'
return limit + ' / ' + limit + ' caracteres.'
}
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment