light.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <style>
  2. .red {
  3. color: #f00;
  4. }
  5. </style>
  6. <template>
  7. <md-layout md-align="center" md-gutter="16">
  8. <md-card>
  9. <md-card-header>
  10. <div class="md-title">{{ light.name }}</div>
  11. <div class="md-subhead">{{ light.type }}</div>
  12. </md-card-header>
  13. <md-card-content>
  14. <md-switch v-model="stateOn" class="md-warn" @change="toggleOnOff()">State</md-switch>
  15. </md-card-content>
  16. <md-card-actions>
  17. <md-button @click.native="reset()">Reset</md-button>
  18. <md-button @click.native="setColor('purple')">Purple</md-button>
  19. <md-button @click.native="colorLoop()">Color Loop</md-button>
  20. </md-card-actions>
  21. </md-card>
  22. </md-layout>
  23. </template>
  24. <script>
  25. module.exports = {
  26. props: ['light'],
  27. data: function () {
  28. return {
  29. stateOn: false
  30. };
  31. },
  32. http: {
  33. root: '/api',
  34. },
  35. methods: {
  36. setProps: function (data) {
  37. this.$http.put('lights/' + this.$props.light.id, data).then(function (result) {
  38. console.log('result', result);
  39. }, function (error) {
  40. console.log('error', error);
  41. });
  42. },
  43. toggleOnOff: function () {
  44. this.stateOn = !this.stateOn;
  45. this.setProps({ state: this.stateOn });
  46. },
  47. reset: function () {
  48. this.setProps({ reset: true });
  49. },
  50. colorLoop: function () {
  51. this.setProps({ effect: 'colorloop' });
  52. },
  53. setColor: function (color) {
  54. this.setProps({ color: color });
  55. }
  56. }
  57. }
  58. </script>