<template> <view class="top-btn"> <view @click="cut(item,index)" v-for="(item,index) in list" :key="index" class="top-btn-item"> {{item}} <view v-if="index == active" class="top-btn-item-color"> </view> </view> </view> </template> <script> export default { name: "topBtn", props: { list: { type: Array, default: () => [] }, active: { type: Number, default: () => 0 } }, data() { return { }; }, methods: { cut(item, index) { this.$emit('update:active', index) this.$emit('click',item) } } } </script> <style lang="scss" scoped> .top-btn { width: 100%; box-sizing: border-box; display: flex; border-bottom: 1px solid #f2f2f2; padding-bottom: 32rpx; background-color: #fff; padding: 32rpx 0; .top-btn-item { flex: 1; display: flex; align-items: center; justify-content: center; position: relative; .top-btn-item-color { width: 150rpx; height: 8rpx; border-radius: 4rpx; background-color: rgba(5, 204, 161, 1); position: absolute; left: 50%; transform: translate(-50%, 0); bottom: -20rpx; } } .top-btn-item:nth-child(1){ border-right: 1px solid #f2f2f2 ; } } </style>