on_off.vue 625 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <template>
  2. <div>
  3. <button @click="handle_click" :class="{ active: value }">
  4. <strong>{{ title }}: {{ value ? "ON" : "OFF" }}</strong>
  5. </button>
  6. </div>
  7. </template>
  8. <script>
  9. export default {
  10. props: {
  11. title: String,
  12. },
  13. data() {
  14. return {
  15. value: false,
  16. };
  17. },
  18. methods: {
  19. handle_click() {
  20. this.value = !this.value;
  21. this.$emit("change", this.value);
  22. },
  23. reset() {
  24. this.value = false;
  25. },
  26. },
  27. };
  28. </script>
  29. <style scoped>
  30. button {
  31. background-color: #eee;
  32. padding: 8px 16px;
  33. border-radius: 4px;
  34. }
  35. button.active {
  36. background-color: #fb8;
  37. }
  38. </style>