graceSegmentedControl.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <view class="gui-segmented-Control" :style="{height:height, background:bgColor}">
  3. <view class="gui-segmented-Control-item" v-for="(item, index) in items" :key="index"
  4. :style="{height:height, lineHeight:height, color:current == index ? '#FFFFFF' : color, background:current == index ? color : '', fontSize:fontSize}"
  5. @tap.stop="changeSC" :data-index="index">{{item}}</view>
  6. </view>
  7. </template>
  8. <script>
  9. export default{
  10. props:{
  11. items : {
  12. type : Array,
  13. default : function () {
  14. return new Array()
  15. }
  16. },
  17. height : {
  18. type : String,
  19. default : '60rpx'
  20. },
  21. bgColor : {
  22. type : String,
  23. default : '#F8F8F8'
  24. },
  25. color : {
  26. type : String,
  27. default : '#3688FF'
  28. },
  29. fontSize : {
  30. type : String,
  31. default : '26rpx'
  32. },
  33. current : {
  34. type : Number,
  35. default : 0
  36. }
  37. },
  38. methods:{
  39. changeSC:function (e) {
  40. this.$emit('change', Number(e.currentTarget.dataset.index));
  41. }
  42. }
  43. }
  44. </script>
  45. <style scoped>
  46. .gui-segmented-Control{display:flex; flex-direction:row; flex-wrap:nowrap; background-color:#F5F6F8; border-radius:10rpx; padding:6rpx; width:100%;}
  47. .gui-segmented-Control-item{width:700rpx; text-align:center; border-radius:8rpx;}
  48. </style>