graceSegmentedControl.nvue 1.4 KB

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