码迷,mamicode.com
首页 > 其他好文 > 详细

vue 实现文本域还剩多少字符

时间:2017-04-09 20:59:23      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:style   doc   script   nbsp   cti   code   doctype   mode   color   

<!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>

 

vue 实现文本域还剩多少字符

标签:style   doc   script   nbsp   cti   code   doctype   mode   color   

原文地址:http://www.cnblogs.com/zhujiasheng/p/6686310.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!