app.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. }
  39. }
  40. Vue.createApp(coinTop50).mount('#app')