vue中限制input只能输入数字-示例

方法1   new Vue({
    el:'#demo',
    data:{
        oldNum:0    
    },
    computed:{
        inpNum:{
            get:function(){
                return this.oldNum;
            
            },
            set:function(newValue){
                this.oldNum=newValue.replace(/[^\d]/g,'');
            }
        }
    }
    
})方法二:
<input type='text' @input="handleInput" :value="val"/>

handleInput(e){
this.val=e.target.value.replace(/[^\d]/g,'');
}


版权声明:本文为zpcqdkf原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。