Skip to content

Instantly share code, notes, and snippets.

@Sundwell
Created July 4, 2023 22:22
Show Gist options
  • Save Sundwell/5a235677102cf7201213db7807e9b8dd to your computer and use it in GitHub Desktop.
Save Sundwell/5a235677102cf7201213db7807e9b8dd to your computer and use it in GitHub Desktop.
Vue.js limit characters length
<template>
<input type="text" :value="value" @input="updateValue" />
{{value}}
</template>
<script>
import { ref } from "vue";
export default {
name: "App",
setup() {
const value = ref('12')
const updateValue = e => {
const val = e.target.value
value.value = val.slice(0, 2)
e.target.value = value.value
}
return {
value,
updateValue
}
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment