vue通过watch对input做字数限定的方法

之前写了关于vue通过watch对input做字数限定的方法,最近需要回顾,就顺便发到随笔上了

<div> <input type="text" v-model="items.text" ref="count"/> <div v-html="number"></div> /div>

new Vue({ el: '#app', data: { number: '100', items: { text:'', }, }, watch:{ //watch()监听某个值(双向绑定)的变化,从而达到change事件监听的效果 items:{ handler:function(){ var _this = this; var _sum = 100; //字体限制为100个 _this.$refs.count.setAttribute("maxlength",_sum); _this.number= _sum- _this.$refs.count.value.length; }, deep:true } } })

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyjszf.html