一.vue在单双行显示不同的样式

解决思路

1.vue在遍历列表时怎么区分是单行还是双行,通过查阅资料vue的v_for in遍历的时候有一个index下标从1开始,通过下标能被2整除的就是双行
2.vue怎么改变元素的样式,通过:class改变元素的class属性或者通过v-bind:style改变便签的style属性

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
<script type="text/javascript" src="vue.js"></script>
	<style>
		.on {
			background: #cdcbff;
		}
		.off {
			background: #fefdff;
		}
	</style>
</head>
<body>
<p>第一个实验:使用vue在单双行显示不同的样式,解决思路</p>
<p>1.vue在遍历列表时怎么区分是单行还是双行,通过查阅资料vue的v_for in遍历的时候有一个index下标从1开始,通过下标能被2整除的就是双行</p>
<p>2.vue怎么改变元素的样式,通过:class改变元素的class属性或者通过v-bind:style改变便签的style属性</p>
<div id="app-4">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<thead>
		<tr>
			<th width="190">奖品名字</th>
			<th align="left">奖品值</th>
			<th align="center">奖品获得人</th>
			<th align="center">创建时间</th>
			<th align="center">奖品id</th>
			<th align="center">点击事件</th>
		</tr>
		</thead>
		<tbody id="luckeyList"  v-for="(todo,index) in todos" :class="{on:index%2==0,off:index%2!=0}">
		<tr><td align="center">{{ todo.name }}</td>
			<td>{{ todo.value }}</td>
			<td align="center">{{ todo.username }}</td>
			<td align="center">{{ todo.c_time }}</td>
			<td align="center">{{ todo.id }}</td>
			<td align="center"><button  @click = "clickHaha(todo)">点击</button></td>

		</tr>
		</tbody>
</table>

</div>
<script>
	var app4 = new Vue({
		el: '#app-4',
		data: {
			todos: [
				{"name":"ivy0","value":"1","id":"0","username":"A**nn","code":"score","c_time":"12-10 11:40:26"},
				{"name":"ivy1","value":"1","id":"1","username":"F**a3","code":"score","c_time":"12-10 11:37:45"},
				{"name":"ivy2","value":"1","id":"2","username":"F**a3","code":"reward_money","c_time":"12-10 11:37:33"},
				{"name":"ivy3","value":"1","id":"3","username":"默**","code":"reward_money","c_time":"12-10 11:32:38"},
				{"name":"ivy4","value":"1","id":"4","username":"默**","code":"score","c_time":"12-10 11:29:55"},
				{"name":"ivy5","value":"1","id":"5","username":"藤**03","code":"score","c_time":"12-10 11:15:09"}
			]
		},
			// 在 `methods` 对象中定义方法
			methods: {
				clickHaha: function (event) {
					alert('Hello ' + event.id + '!')

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

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值