topBtn.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <view class="top-btn">
  3. <view @click="cut(item,index)" v-for="(item,index) in list" :key="index" class="top-btn-item">
  4. {{item}}
  5. <view v-if="index == active" class="top-btn-item-color">
  6. </view>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. name: "topBtn",
  13. props: {
  14. list: {
  15. type: Array,
  16. default: () => []
  17. },
  18. active: {
  19. type: Number,
  20. default: () => 0
  21. }
  22. },
  23. data() {
  24. return {
  25. };
  26. },
  27. methods: {
  28. cut(item, index) {
  29. this.$emit('update:active', index)
  30. this.$emit('click',item)
  31. }
  32. }
  33. }
  34. </script>
  35. <style lang="scss" scoped>
  36. .top-btn {
  37. width: 100%;
  38. box-sizing: border-box;
  39. display: flex;
  40. border-bottom: 1px solid #f2f2f2;
  41. padding-bottom: 32rpx;
  42. background-color: #fff;
  43. padding: 32rpx 0;
  44. .top-btn-item {
  45. flex: 1;
  46. display: flex;
  47. align-items: center;
  48. justify-content: center;
  49. position: relative;
  50. .top-btn-item-color {
  51. width: 150rpx;
  52. height: 8rpx;
  53. border-radius: 4rpx;
  54. background-color: rgba(5, 204, 161, 1);
  55. position: absolute;
  56. left: 50%;
  57. transform: translate(-50%, 0);
  58. bottom: -20rpx;
  59. }
  60. }
  61. .top-btn-item:nth-child(1){
  62. border-right: 1px solid #f2f2f2 ;
  63. }
  64. }
  65. </style>