btn.vue 786 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <view class="btn">
  3. <view @click="itemClick(item,index)" :class="active == index ? 'active' : ''" v-for="(item,index) in list"
  4. :key="index" class="btn-item">
  5. {{item}}
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. export default {
  11. name: "btn",
  12. props: {
  13. list: {
  14. type: Array,
  15. default: () => []
  16. }
  17. },
  18. data() {
  19. return {
  20. active: 0
  21. };
  22. },
  23. methods: {
  24. itemClick(item, index) {
  25. this.active = index
  26. }
  27. }
  28. }
  29. </script>
  30. <style lang="scss" scoped>
  31. .btn {
  32. display: flex;
  33. .btn-item {
  34. width: 144rpx;
  35. height: 64rpx;
  36. background: #e4fff9;
  37. border-radius: 10rpx;
  38. text-align: center;
  39. line-height: 64rpx;
  40. color: #05CCA1;
  41. margin-right: 20rpx;
  42. }
  43. .active {
  44. background-color: #05CCA1;
  45. color: #fff;
  46. }
  47. }
  48. </style>