vue input只允许输入数字

template:

<input 
    type="text"
    v-model="pageIndex"
    @keyup="inputChange"
>

 

JS:

methods: {
    inputChange() { //输入框值改变
        this.pageIndex = this.pageIndex.replace(/[^\d]/g, '')
    }
}

 

其它input事件:

@change

@keyup

@keydown

@bulr

 

PS:

这里的例子只是单纯的用了input标签,如果你使用了UI框架的话,那么对应的监听事件就要换成UI框架里的事件,比如 element-ui 里的 el-input 标签里的监听事件为 input 那么就要把例子中的 @keyup 改为 @input

 

posted @ 2019-10-17 14:47  青芒灬  阅读(23125)  评论(0编辑  收藏  举报