Created
July 4, 2023 22:22
-
-
Save Sundwell/5a235677102cf7201213db7807e9b8dd to your computer and use it in GitHub Desktop.
Vue.js limit characters length
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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