<!DOCTYPE html>
<html>
<head>
	<title>vue</title>
	<meta charset="utf-8">
	<script type="text/javascript" src="lodash.min.js"></script>
	<script type="text/javascript" src="vue.js"></script>
	<style type="text/css">
		*{margin:0;padding:0;}
		table,tr,th,td{border:1px solid #ccc;}
		#page{width:1000px;margin:40px auto;}
		#page table{width:100%;}
		#page .box{
			margin-top:30px;
		}
	</style>
</head>
<body>
    <div id="page">
    	<table>
    		<tr>
    		    <th>开始时间</th>
    			<th>结束时间</th>
    			<th>姓名</th>
    			<th>年龄</th>
    			<th>性别</th>
    			<th>操作</th>
    		</tr>
    		<tr v-for="item in list">
    		    <td><input type="text" v-model="item.start" ></td>
    		    <td><input type="text" v-model="item.end" ></td>
    			<td><input type="text" v-model="item.name" ></td>
    			<td><input type="text" v-model="item.age"></td>
    			<td><input type="text" v-model="item.sex"></td>
    			<td>
    				<button @click="add($index)">添加</button>  
    				<button @click="remove($index)">删除</button>
    			</td>
    		</tr>
    	</table>

    	<div class="box">
    		{{calcRes}}
    	</div>
    </div>
	<script type="text/javascript">
		new Vue({
			el:'#page',
			data:{
				list:[
					{start:24,end:3223,name:'zjs',age:23,sex:'boy'}
				]
			},
			methods:{
				add:function(parm){
                   var obj = {start:0,end:0,name:'',age:'',sex:''};
                   this.list.splice(parm+1,0,obj);
				},
				remove:function(parm){
				   if(this.list.length>1){
				   	 this.list.splice(parm,1);
				   	}else{
				   		alert("至少有一条")
				   	}
				}
			},
			computed:{
               calcRes:function(){
               	  var total = [];
               	  var days = 0;
                  for(var i = 0; i < this.list.length; i++){
                  	  var arr = [];
                  	  if( parseInt(this.list[i].end) - parseInt(this.list[i].start) >= 0){
                  	  	 this.list[i].name ? arr.push(this.list[i].name) : '';
                         this.list[i].age ? arr.push(this.list[i].age) : '';
                         this.list[i].sex ? arr.push(this.list[i].sex) : '';
                         if(this.list[i].name || this.list[i].age || this.list[i].sex){
                             total.push(_.uniq(arr).length + 1);
                         }
                  	  }else{
                  	  	alert("第"+(i+1)+"有问题");
                  	  	continue;
                  	  }
                  }
                  for(var j = 0; j < total.length; j++){
                        days += total[j];
                  }
                  return days;
               }
			},
			ready:function(){

			}
		})
	</script>
</body>
</html>

  

<!DOCTYPE html> <html> <head> <title>vue</title> <meta charset="utf-8"> <script type="text/javascript" src="lodash.min.js"></script> <script type="text/javascript" src="vue.js"></script> <style type="text/css"> *{margin:0;padding:0;} table,tr,th,td{border:1px solid #ccc;} #page{width:1000px;margin:40px auto;} #page table{width:100%;} #page .box{ margin-top:30px; } </style> </head> <body> <div id="page"> <table> <tr> <th>开始时间</th> <th>结束时间</th> <th>姓名</th> <th>年龄</th> <th>性别</th> <th>操作</th> </tr> <tr v-for="item in list"> <td><input type="text" v-model="item.start" ></td> <td><input type="text" v-model="item.end" ></td> <td><input type="text" v-model="item.name" ></td> <td><input type="text" v-model="item.age"></td> <td><input type="text" v-model="item.sex"></td> <td> <button @click="add($index)">添加</button>   <button @click="remove($index)">删除</button> </td> </tr> </table> <div class="box"> {{calcRes}} </div> </div> <script type="text/javascript"> new Vue({ el:'#page', data:{ list:[ {start:2423423,end:3223,name:'zjs',age:23,sex:'boy'} ] }, methods:{ add:function(parm){ var obj = {start:0,end:0,name:'',age:'',sex:''}; this.list.splice(parm+1,0,obj); }, remove:function(parm){ if(this.list.length>1){ this.list.splice(parm,1); }else{ alert("至少有一条") } } }, computed:{ calcRes:function(){ var total = []; var days = 0; for(var i = 0; i < this.list.length; i++){ var arr = []; if( parseInt(this.list[i].end) - parseInt(this.list[i].start) >= 0){ this.list[i].name ? arr.push(this.list[i].name) : ''; this.list[i].age ? arr.push(this.list[i].age) : ''; this.list[i].sex ? arr.push(this.list[i].sex) : ''; if(this.list[i].name || this.list[i].age || this.list[i].sex){ total.push(_.uniq(arr).length + 1); } } } for(var j = 0; j < total.length; j++){ days += total[j]; } return days; } }, ready:function(){ } }) </script> </body> </html>

  

vue computed自动计算的更多相关文章

  1. vue computed 原理

    vue computed 主要依靠数据依赖来更新,这里不展示computed源代码,只展示核心思想. computed: { a(){ return this.b ++ } } data:{ b: 1 ...

  2. Vue computed props pass params

    Vue computed props pass params vue 计算属性传参数 // 计算 spreaderAlias spreaderAlias () { console.log('this. ...

  3. vuex bug & vue computed setter

    vuex bug & vue computed setter https://vuejs.org/v2/guide/computed.html#Computed-Setter [Vue war ...

  4. vue computed、methods、watch的区别

    1.computed(计算属性)computed是计算属性,事实上和和data对象里的数据属性是同一类的(使用上), 2.methods(方法)写在html中的时候需要带()支持传参,且需要有触发条件 ...

  5. Vue computed属性

    computed vs methods 我们可以使用Vue中的method计算出学科的总分,最终得到的总数结果是相同的. 在上例的基础上,我们把computed区块中的totalMarks函数整体移到 ...

  6. 深入理解 Vue Computed 计算属性

    Computed 计算属性是 Vue 中常用的一个功能,我们今天来说一下他的执行过长 拿官网简单的例子来看一下: <div id="example"> <p> ...

  7. vue computed的执行问题

    1.在new Vue()的时候,vue\src\core\instance\index.js里面的_init()初始化各个功能 function Vue (options) { if (process ...

  8. vue computed 可以使用getter和setter

    var vm = new Vue({ data: { a: 1 }, computed: { // 仅读取 aDouble: function () { return this.a * 2 }, // ...

  9. Vue -computed传参数

    vue 中computed想传递参数怎么办? 闭包在这里起到的重要的作用 <input v-model="newItem(key,val)" type="text& ...

随机推荐

  1. _00017 Kafka的体系结构介绍以及Kafka入门案例(0基础案例+Java API的使用)

    博文作者:妳那伊抹微笑 itdog8 地址链接 : http://www.itdog8.com(个人链接) 博客地址:http://blog.csdn.net/u012185296 博文标题:_000 ...

  2. GitBlit中出现 error: remote unpack failed: error Missing tree

    clu@WASYGSHA01-1020 MINGW64 /d/ChuckLu/Git/Edenred/LISA_5.0.0.0 (local)$ git push origin preaction:p ...

  3. 14.MongoDBUtils工具类

    1. public class DbUtils { public static MongoCollection<Document> getMongoCollection(String lo ...

  4. Vmware Workstation及Centos6.8 的安装

    转自:http://www.mamicode.com/info-detail-1462939.html 一.什么是Vmware Workstation Vmware Workstation是Vmwar ...

  5. xBIM 基础09 WeXplorer 基本应用

    系列目录    [已更新最新开发文章,点击查看详细]  在本教程中,将学习如何创建最基本和最直接的查看器. 除了展示建筑模型外,不做其他任何操作.它将只使用内置导航,但是不会对按钮做出事件响应. &l ...

  6. Quartz介绍和使用

    Quartz介绍和使用 什么是Quartz,干什么的? Quartz框架是一个全功能.开源的任务调度服务,可以集成几乎任何的java应用程序—从小的单片机系统到大型的电子商务系统.Quartz可以执行 ...

  7. 引用axiv文献的问题

    首先找了一下对8种常见引用格式进行说明的文章 https://blog.csdn.net/wkd22775/article/details/51798927 然后就是水木社区大神们的记录http:// ...

  8. iOS Device Types

    ios 设备硬件名称对照表 https://support.hockeyapp.net/kb/client-integration-ios-mac-os-x-tvos/ios-device-types ...

  9. HDU 1312 Red and Black【DFS】

    搜索虐我千万遍@_@-----一道搜索的水题,WA了好多好多次@_@发现是n,m搞反了-_- 题意-- 给出m行 n列的矩形,其中从@出发,不能跳到#,只能跳到'.'问最多能够跳到多少块'.' 直接搜 ...

  10. SpringBoot学习笔记(15)----SpringBoot使用Druid

    直接访问Druid官网wiki,有详细教程,地址如下: SpringBoot支持Druid地址:https://github.com/alibaba/druid/tree/master/druid-s ...