p-checkbox.vue 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <view class="checkbox" :class="isOpen ? 'active' : ''" @click="handleToggle">
  3. <text v-show="isOpen"></text>
  4. <view class="circle"></view>
  5. <text v-show="!isOpen"></text>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. props: {
  11. isOpen: {
  12. required: true,
  13. type: Boolean,
  14. default: false
  15. }
  16. },
  17. data() {
  18. return {};
  19. },
  20. methods: {
  21. handleToggle() {
  22. this.$emit('toggle');
  23. }
  24. }
  25. };
  26. </script>
  27. <style scoped lang="scss">
  28. .active {
  29. background-color: #3c78ff !important;
  30. }
  31. .checkbox {
  32. width: 100rpx;
  33. height: 40rpx;
  34. padding: 4rpx;
  35. border-radius: 24rpx;
  36. background-color: #c3c8cc;
  37. display: flex;
  38. justify-content: flex-start;
  39. align-items: center;
  40. > .circle {
  41. width: 40rpx;
  42. height: 40rpx;
  43. background-color: white;
  44. border-radius: 50%;
  45. }
  46. > text {
  47. flex: 1;
  48. font-size: 24rpx;
  49. color: white;
  50. &:first-of-type {
  51. text-align: left;
  52. margin-left: 16rpx;
  53. }
  54. &:last-of-type {
  55. text-align: right;
  56. margin-right: 16rpx;
  57. }
  58. }
  59. }
  60. </style>