Vue动态给一个元素添加类名,兄弟元素移除类名

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/marko_zheng/article/details/83657284

Vue动态给一个元素添加类名,兄弟元素移除类名

直接上代码,亲测可用

<template>
 	<div>
		<ul>
			<li  v-for="(item,index) in list" @click="do(item,index)" :class="{'color':index==current}">{{item.name}}</li>
		</ul>
	</div>
</template>
<script>
	export default {
		name:"ul",
		data(){
			return{
				current:0,
				list:[
					{name:"zhangsan",age:14},	
					{name:"zhangsan",age:14},	
					{name:"zhangsan",age:14},	
					{name:"zhangsan",age:14},	
				]	
			}
		},
		methods:{
			do(item,index){
				//item,进行相关操作
				this.current = index
			}
		}
		
	}
</script>
<style scope>
.color{color:#fff}
</style>

猜你喜欢

转载自blog.csdn.net/marko_zheng/article/details/83657284
今日推荐