之前写了关于vue通过watch对input做字数限定的方法,最近需要回顾,就顺便发到随笔上了
<div id="app"> <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    }  }})以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持武林网。
新闻热点
疑难解答