<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <script src="http://cn.vuejs.org/js/vue.js"></script> </head> <body> <div id="app"> <template v-for="(item,index) in msg"> <textarea :maxlength ="checkLength(index)" v-model="item.name" cols="30" rows="10" ></textarea> <span v-if="index == 1">还可以输入{{10- result[index]}}字符</span> </template> </div> <script> var vm = new Vue({ el:‘#app‘, data:{ msg:[ {"name":""}, {"name":""}, {"name":""} ] }, methods:{ checkLength:function(index){ return index <= 1 ? 10: ‘‘ } }, computed:{ result:function(){ var l = 0; var arr = []; var reg = /^[\s]$/g; for(var i=0; i<this.msg.length; i++){ l = (this.msg[i].name).toString().replace(/\s/g,"").length; arr.push(l); } return arr; } } }) </script> </body> </html>
时间: 2024-10-13 02:40:54