39,082
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<style>
.active {
color: red;
}
</style>
</head>
<body>
<script src="./common/vue@2.3.3.js"></script>
<div id="app">
<table>
<tr>
<td v-for="(item,index) in head" @click="change(index)" :class="{active:item.active}"
>{{item.name}}
</td>
</tr>
</table>
</div>
<script>
new Vue({
el: '#app',
data: {
head: [{
name: 'name'
}, {
name: 'age'
}]
},
methods: {
change: function (index) {
this.head=this.head.map(function (item,i) {
i===index&&(item.active = true);
return item
})
}
}
})
</script>
</body>
</html>