i have a text box only want accept "Number" and ".[dot]" using Vue.js, anyone can help the code? i'm new on vue.
相关问题
- Axios OPTIONS instead of POST Request. Express Res
- Vue.js - set slot content programmatically
- Getting Uncaught TypeError: …default is not a cons
- Vue.js computed property loses its reactivity when
- How to remove the Vuetify append-icon from the seq
相关文章
- Best way to dynamically change theme of my Vue.js
- vue-router how to persist navbar?
- How to Properly Use Vue Router beforeRouteEnter or
- Difference between nameFunction() {} and nameFunct
- Vue - best way to reuse methods
- setTimeout() not working called from vueJS method
- How to unbind an array copy in Vue.js
- Vue Cli 3 Local fonts not loading
You can write a Vue method and that method can be called on the keypress event. Check out this fiddle.
Update:
adding source code:
HTML
Vue.js
I needed my input to allow only digits, so no
e
symbol, plus, minus or or.
. Vue seems funky and doesn't re-trigger @onkeypress for symbols likedot
.Here is my solution to this problem:
I am taking digits only, limiting from 0 to 9, but also I do want enable form submit on Enter, which would be excluded with the above approach - thus the enter.
You should change your input to
type="number"
to more accurately reflect your behaviour. You can then use the built-in Vue.js directivev-model.number
.Usage:
A simple way to do this in one line:
I cannot the perfect solution as some work for inputing but not for copy&paste, some are the other way around. This solution works for me. It prevents from negative number, typing "e", copy&paste "e" text.
I use mixin so I can be resued anywhere.
In your component, add to your input.