main.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. var util = require('util');
  2. var Vue = require('vue'),
  3. VueMaterial = require('vue-material'),
  4. VueResource = require('vue-resource');
  5. var Light = require('../views/light.vue');
  6. Vue.use(VueMaterial);
  7. Vue.use(VueResource);
  8. var App = new Vue({
  9. el: '#app',
  10. http: {
  11. root: '/api',
  12. },
  13. components: {
  14. lightItem: Light
  15. },
  16. data: {
  17. lights: [],
  18. selectedLight: {}
  19. },
  20. methods: {
  21. toggleSidenav: function () {
  22. this.$refs.leftSidenav.toggle();
  23. },
  24. sidenavOpen: function () {
  25. console.log('sidenav open');
  26. },
  27. selectLight: function (light) {
  28. this.$data.selectedLight = light;
  29. this.$refs.leftSidenav.close();
  30. }
  31. },
  32. mounted: function () {
  33. console.log('mounted');
  34. var that = this;
  35. this.$http.get('lights', { responseType: 'text' }).then(function (result) {
  36. console.log('result', result);
  37. that.$data.lights = result.body.lights;
  38. that.$data.selectedLight = result.body.lights[3];
  39. }, function (error) {
  40. console.log('error', error);
  41. });
  42. }
  43. });