index.vue 1009 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <view class="tab-radio-container" :style="{ gridTemplateColumns: `repeat(${colNum}, 1fr)` }">
  3. <view
  4. class="tab-item"
  5. v-for="(item, index) in tabList"
  6. :key="index"
  7. :class="{ 'tab-item--active': activeValue === item.value }"
  8. @click="handleTabClick(item)"
  9. >
  10. <text class="tab-item__text">{{ item.name }}</text>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. name: "TabRadio",
  17. props: {
  18. tabList: {
  19. type: Array,
  20. required: true,
  21. default: () => []
  22. },
  23. defaultActive: {
  24. type: [String, Number],
  25. default: ""
  26. },
  27. colNum: {
  28. type: Number,
  29. default: 4
  30. }
  31. },
  32. data() {
  33. return {
  34. activeValue: this.defaultActive
  35. };
  36. },
  37. methods: {
  38. handleTabClick(item) {
  39. this.activeValue = item.value;
  40. this.$emit("tabChange", {
  41. name: item.name,
  42. value: item.value
  43. });
  44. }
  45. }
  46. };
  47. </script>
  48. <style lang="scss" scoped>
  49. @import "./index.scss";
  50. </style>