app.js 900 B

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