listOption_line.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view class="list-wrap">
  3. <view
  4. class="item"
  5. v-for="(item, index) in list"
  6. :key="index"
  7. :class="isActive(item)"
  8. @click="change(item)"
  9. >
  10. {{ item[label] }}
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. model: {
  17. prop: 'active',
  18. event: 'change'
  19. },
  20. props: {
  21. list: {
  22. type: Array,
  23. default () {
  24. return []
  25. }
  26. },
  27. active: {
  28. type: [Number, String]
  29. },
  30. label: {
  31. type: String,
  32. default: 'label'
  33. },
  34. value: {
  35. type: String,
  36. default () {
  37. return 'value'
  38. }
  39. }
  40. },
  41. methods: {
  42. isActive (item) {
  43. if (this.active === item[this.value]) {
  44. return 'active'
  45. } else {
  46. return ''
  47. }
  48. },
  49. change (item) {
  50. this.$emit('change', item[this.value])
  51. }
  52. }
  53. }
  54. </script>
  55. <style lang="scss" scoped>
  56. .list-wrap {
  57. .item {
  58. display: flex;
  59. justify-content: flex-start;
  60. align-items: center;
  61. font-size: 28rpx;
  62. color: #333333;
  63. box-sizing: border-box;
  64. height: 100rpx;
  65. padding-left: 30rpx;
  66. border-bottom: 1px solid #f2f2f2;
  67. }
  68. & .active {
  69. background-color: #caf982;
  70. }
  71. }
  72. </style>