graceSegmentedControl.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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="{
  5. height:height, lineHeight:height,
  6. color:currentIn == index ? '#FFFFFF' : color,
  7. background:currentIn == index ? color : '', fontSize:fontSize}"
  8. @tap.stop="changeSC" :data-index="index">{{item}}</view>
  9. </view>
  10. </template>
  11. <script>
  12. export default{
  13. props:{
  14. items : {
  15. type : Array,
  16. default : function () {
  17. return new Array()
  18. }
  19. },
  20. height : {
  21. type : String,
  22. default : '60rpx'
  23. },
  24. bgColor : {
  25. type : String,
  26. default : '#F8F8F8'
  27. },
  28. color : {
  29. type : String,
  30. default : '#3688FF'
  31. },
  32. fontSize : {
  33. type : String,
  34. default : '26rpx'
  35. },
  36. current : {
  37. type : Number,
  38. default : 0
  39. }
  40. },
  41. data() {
  42. return {
  43. currentIn: 0
  44. }
  45. },
  46. created: function(){
  47. this.currentIn = this.current;
  48. },
  49. watch:{
  50. current : function (val) {
  51. this.currentIn = val;
  52. }
  53. },
  54. methods:{
  55. changeSC:function (e) {
  56. var index = Number(e.currentTarget.dataset.index);
  57. this.currentIn = index;
  58. this.$emit('change', index);
  59. }
  60. }
  61. }
  62. </script>
  63. <style scoped>
  64. .gui-segmented-Control{display:flex; flex-direction:row; flex-wrap:nowrap; background-color:#F5F6F8; border-radius:10rpx; padding:6rpx; width:100%;}
  65. .gui-segmented-Control-item{width:700rpx; text-align:center; border-radius:8rpx;}
  66. </style>