gui-segmented-control.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <template>
  2. <view class="gui-flex gui-rows gui-nowrap gui-justify-content-center gui-segmented-control"
  3. :style="{borderRadius:borderRadius}">
  4. <text v-for="(item, index) in items" :key="index"
  5. :class="['gui-segmented-control-item','gui-block-text',
  6. index == currentIn ? 'gui-segmented-current':'',
  7. index == currentIn ? 'gui-fade-in':'']"
  8. :style="{borderRadius:borderRadius}"
  9. @tap.stop="changeSC" :data-index="index">{{item}}</text>
  10. </view>
  11. </template>
  12. <script>
  13. export default{
  14. name : "gui-segmented-control",
  15. props : {
  16. items : {
  17. type : Array,
  18. default : function () { return new Array();}
  19. },
  20. current : { type : Number, default : 0},
  21. borderRadius:{type:String, default:'6rpx'}
  22. },
  23. data() {
  24. return {
  25. currentIn: 0
  26. }
  27. },
  28. created: function(){
  29. this.currentIn = this.current;
  30. },
  31. watch:{
  32. current : function (val) {
  33. this.currentIn = val;
  34. }
  35. },
  36. methods:{
  37. changeSC:function (e) {
  38. var index = Number(e.currentTarget.dataset.index);
  39. this.currentIn = index;
  40. this.$emit('change', index);
  41. }
  42. }
  43. }
  44. </script>
  45. <style scoped>
  46. .gui-segmented-control-item{width:50rpx; flex:1; text-align:center;}
  47. </style>