app.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const MIN_DATE = dayjs("2014-01-01")
  2. const RANGE_MAX = dayjs().diff(MIN_DATE,"d")
  3. const coinTop50 = {
  4. data() {
  5. return {
  6. date :document.getElementById("startDate").innerText,
  7. items: [],
  8. rangeDate:RANGE_MAX,
  9. maxRange:RANGE_MAX,
  10. datepicker:null
  11. }
  12. },
  13. mounted() {
  14. this.requestData(this.date)
  15. const elems = document.querySelectorAll('.datepicker');
  16. this.datepicker = M.Datepicker.init(elems, {onClose:()=>{
  17. this.date = this.datepicker.date.toISOString().slice(0,10)
  18. }})[0];
  19. },
  20. watch:{
  21. date(newDate,oldDate){
  22. this.requestData(newDate)
  23. },
  24. rangeDate(newValue){
  25. this.date = MIN_DATE.add(newValue,"d").format("YYYY-MM-DD");
  26. }
  27. },
  28. methods:{
  29. requestData(sDate){
  30. const d = new Date(sDate)
  31. const url = `/top50json/${d.getDate()}-${("0"+(d.getMonth()+1)).slice(-2)}-${d.getFullYear()}/`;
  32. axios.get(url)
  33. .then(this.handleJsonUpdate)
  34. },
  35. handleJsonUpdate(response){
  36. this.items = response.data
  37. },
  38. displayRoundedPrice(price){
  39. var precision = -Math.floor( Math.log10(price) + 1);
  40. return Math.round(item.prices.toFixed(precision)).toLocaleString();
  41. }
  42. }
  43. }
  44. Vue.createApp(coinTop50).mount('#app')