用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - javascript代码库

vue.js合算功能

2016-10-18 作者: 云代码会员举报

[javascript]代码库

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Examples</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
<script type="text/javascript" src="vue.js"></script>
<style type="text/css">
	[v-cloak] {
  display: none;
}
*{
	margin:0;
	padding:0;
}
body{
    font-family:Microsoft YaHei;
}
li{list-style:none;}
div{
    width:400px;
    background-color:#61a1bc;
    margin:50px auto;
    padding:35px 60px;
}
h1{
    font-size:44px;
    text-align:center; 
}
ul{
    font-size:20px;
    text-align:left;
    margin:20px 0 15px;
}
ul li{
    padding:20px 30px;
	background-color:#e35885;
	margin-bottom:8px;
	cursor:pointer;
}
ul li span{float:right;}
ul li.active{
    background-color:#8ec16d;
}
p{
    border-top:1px solid rgba(255,255,255,0.5);
	padding:15px 30px;
	font-size:20px;
	text-align: left;
}
p span{float:right;}

</style>
</head>
<body>
    <div id="main" v-cloak>
    <h1>Services</h1>
    <ul>
        <li v-for="item in items" @click="toggleActive(item)" :class="{'active':item.active}">{{item.name}}<span>{{item.price | currency}}</span></li>
    </ul>
    <p>Total: <span>{{total() | currency}}</span></p>
</div>
</body>
<script type="text/javascript">
	var demo = new Vue({
    el: '#main',
    data: {
        items: [
        	{
        		name: 'Web Development',
        		price: 300,
        		active:false
        	},{
        		name: 'Design',
        		price: 400,
        		active:false
        	},{
        		name: 'Integration',
        		price: 250,
        		active:false
        	},{
        		name: 'Training',
        		price: 220,
        		active:false
        	}
        ]
    },
    methods: {
    	toggleActive: function(i){
            i.active = !i.active;
    	},
    	total: function(){
        	var total = 0;
        	this.items.forEach(function(s){
        		if (s.active){
        			total+= s.price;
        		}
        	});
    	   return total;
        }
    }
});
</script>
</html>


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...