switch-bar.vue 873 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <view class="switch-bar">
  3. <text class="title">{{ title }}</text>
  4. <switch class="switch" :checked="checked" color="#18bc37" @change="onChange"></switch>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. name: "switch-bar",
  10. props: {
  11. title: {
  12. type: String,
  13. required: true
  14. },
  15. checked: {
  16. type: Boolean,
  17. default: false
  18. }
  19. },
  20. data() {
  21. return {
  22. value: this.checked
  23. }
  24. },
  25. methods: {
  26. onChange(e) {
  27. this.value = true;
  28. setTimeout(() => {
  29. this.value = false;
  30. }, 100)
  31. //this.value = false;
  32. this.$emit('change', e);
  33. }
  34. }
  35. }
  36. </script>
  37. <style lang="scss" scoped>
  38. .switch-bar {
  39. width: 100%;
  40. height: 100rpx;
  41. font-size: 34rpx;
  42. color: black;
  43. margin-top: 5rpx;
  44. background-color: white;
  45. line-height: 100rpx;
  46. display: flex;
  47. .title {
  48. flex: 1;
  49. margin-left: 40rpx;
  50. }
  51. .switch {
  52. margin-right: 40rpx;
  53. }
  54. }
  55. </style>