<template> <view class="btn"> <view @click="itemClick(item,index)" :class="active == index ? 'active' : ''" v-for="(item,index) in list" :key="index" class="btn-item"> {{item}} </view> </view> </template> <script> export default { name: "btn", props: { list: { type: Array, default: () => [] } }, data() { return { active: 0 }; }, methods: { itemClick(item, index) { this.active = index } } } </script> <style lang="scss" scoped> .btn { display: flex; .btn-item { width: 144rpx; height: 64rpx; background: #e4fff9; border-radius: 10rpx; text-align: center; line-height: 64rpx; color: #05CCA1; margin-right: 20rpx; } .active { background-color: #05CCA1; color: #fff; } } </style>