12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <template>
- <div>
- <input
- :maxLength="maxLength"
- @input="emitInputValue"
- @blur="v.$touch()"
- type="text"
- placeholder="e.g. Amazing Course in Flutter!"
- class="input is-large">
- <span class="icon is-small is-right">
- {{remainingLength}}
- </span>
- </div>
- </template>
- <script>
- export default {
- data() {
- return {
- currentValue: ''
- }
- },
- props: {
- maxLength: {
- type: Number,
- default: 50,
- required: false
- },
- v: {
- type: Object,
- required: true,
- }
- },
- computed : {
- inputLength() {
- return this.currentValue.length || 0
- },
- remainingLength(){
- if (this.inputLength > 0 && this.inputLength < this.maxLength) {
- return this.maxLength - this.inputLength
- } else if (this.inputLength === 0) {
- return this.maxLength
- } else {
- return 0
- }
- }
- },
- methods : {
- emitInputValue($event) {
- this.currentValue = $event.target.value
- this.$emit('input', this.currentValue)
- }
- }
- }
- </script>
|