v-for循环el-button默认选中第一个button按钮,执行第一个按钮的事件

需求: v-for遍历一组按钮,要做到一进入页面高亮就在第一个按钮上面,且执行第一个按钮的方法

<template>
	<el-button
		v-for="(item,index) in upList"
		:key="index"
		size="small"
		:class="{ active: index == upBtn }"
		style="margin-bottom:10px"
		@click="handle(item,index)"
	>{{item.name}}</el-button>
</template>

data中定义upBtn

data(){
	return{
		// 用于按钮高亮设置
		upBtn: 0,
	}
}

实现一进入页面就执行第一个按钮:

watch: {
	upList: {
		handler(newVal,oldVal){
			this.handler(newVal[0],0)
		}
	}
}

按钮方法

methods: {
	handle(row,index){
		// 
		this.upBtn = index
		...
	}
}

按钮高亮展示

<style scoped>
.active {
	color: #1890ff;
	border-color: #badeff;
	background-color:#e8f4ff
}
</style>
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值