index.vue 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <view class="jnpf-switch">
  3. <u-switch v-model="innerValue" :active-value="activeValue" :inactive-value="inactiveValue" :disabled="disabled"
  4. @change="onChange" :size="size"></u-switch>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. name: 'jnpf-switch',
  10. props: {
  11. modelValue: {
  12. type: [String, Number, Boolean],
  13. },
  14. activeValue: {
  15. type: [String, Number, Boolean],
  16. default: 1
  17. },
  18. inactiveValue: {
  19. type: [String, Number, Boolean],
  20. default: 0
  21. },
  22. size: {
  23. default: 40
  24. },
  25. disabled: {
  26. type: Boolean,
  27. default: false
  28. },
  29. },
  30. data() {
  31. return {
  32. innerValue: ''
  33. }
  34. },
  35. watch: {
  36. modelValue: {
  37. handler(val) {
  38. this.innerValue = !!Number(val)
  39. },
  40. immediate: true,
  41. }
  42. },
  43. methods: {
  44. onChange(val) {
  45. this.$emit('update:modelValue', val)
  46. this.$emit('change', val)
  47. },
  48. }
  49. }
  50. </script>
  51. <style scoped lang="scss">
  52. .jnpf-switch {
  53. width: 100%;
  54. display: flex;
  55. justify-content: flex-end;
  56. align-items: center;
  57. }
  58. </style>