var app= new Vue({
el: '#app',
data: {
},
computed: {
},
directives: {
numberOnly: {
bind: function (el) {
el.handler = function () {
el.value = el.value.replace(/\D+/, '')
}
el.addEventListener('input', el.handler)
},
unbind: function (el) {
el.removeEventListener('input', el.handler)
}
}
},
methods: {
}
});
<input placeholder="0" v-number-only />
驼峰 横杠