app.js 1.1 KB

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