app.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. Number.prototype.currency = function() { return '$' + this.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,') };
  2. function log() {
  3. console.log('LOG >>>', arguments);
  4. }
  5. function get_items() {
  6. var xhr = new XMLHttpRequest();
  7. xhr.onload = function() {
  8. var data = {};
  9. try {
  10. data = JSON.parse(xhr.responseText);
  11. } catch(e){
  12. log('could not parse JSON');
  13. }
  14. app.items = data;
  15. };
  16. xhr.open('GET', 'db.json', true);
  17. try {
  18. xhr.send();
  19. } catch(e) {
  20. log('err', e);
  21. }
  22. }
  23. var app = new Vue({
  24. el: '#app',
  25. data: {
  26. title: "egunner",
  27. items: {},
  28. debug: false
  29. },
  30. mounted: function () {
  31. // hide splash
  32. var splash = document.getElementById("splash");
  33. splash.style.display = "none";
  34. // unhide main container after mount
  35. this.$el.style.display = "block";
  36. },
  37. computed: {
  38. },
  39. methods: {
  40. },
  41. watch: {
  42. },
  43. });
  44. get_items();
  45. window.setInterval(function(){
  46. console.log('refresh');
  47. get_items();
  48. }, 5000);