fa-switch.vue 810 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <view><u-switch v-model="switchCheck" :active-color="theme.bgColor" @change="switchChange"></u-switch></view>
  3. </template>
  4. <script>
  5. import Emitter from '@/uni_modules/uview-ui/libs/util/emitter.js';
  6. export default {
  7. name: 'fa-switch',
  8. mixins: [Emitter],
  9. props: {
  10. value: {
  11. type: [String, Number],
  12. default: 0
  13. },
  14. defvalue: {
  15. type: [String, Number],
  16. default: 0
  17. }
  18. },
  19. watch: {
  20. defvalue: {
  21. immediate: true,
  22. handler(newValue, oldValue) {
  23. this.switchCheck = newValue == 1;
  24. }
  25. }
  26. },
  27. data() {
  28. return {
  29. switchCheck: false
  30. };
  31. },
  32. methods: {
  33. switchChange(e) {
  34. let value = e ? '1' : '0';
  35. this.$emit('input', value);
  36. setTimeout(() => {
  37. this.dispatch('u-form-item', 'on-form-blur', value);
  38. }, 50);
  39. }
  40. }
  41. };
  42. </script>
  43. <style lang="scss"></style>