How can I get month moment js in loop on the vue?

非 Y 不嫁゛ 提交于 2019-12-11 10:54:31

问题


I have a problem

Look at this : https://codepen.io/positivethinking639/pen/YzzWyaR?editors=1010

If the script executed, the result of console.log(date) is

Whereas from my script should the result

2019-10-01
2019-10-02
...
...
2019-10-31

why the results don't match?

if I choose next month, the results will also not match


回答1:


Updated for loop initialisation for(var i = 1; i <= totalDay; i++) { and let date = moment().month(val.split('-')[1]-1).date(i).format("YYYY-MM-DD")

Now it works as expected

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data: () => ({
    date: '2019-10-15',
    id: 5
  }),
  methods: {
    pickerUpdate: async function(val, id) {
      let totalDay = moment(val, "YYYY-MM").daysInMonth() 
      console.log(totalDay)
      for(var i = 1; i <= totalDay; i++) {
        let date = moment().month(val.split('-')[1]-1).date(i).format("YYYY-MM-DD")
        console.log(date)
      }

    },
  },

})

codepen here: https://codepen.io/chansv/pen/dyyXYgQ?editors=1010



来源:https://stackoverflow.com/questions/58403756/how-can-i-get-month-moment-js-in-loop-on-the-vue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!