如何在Vue上循环获取月份矩js? [英] How can I get month moment js in loop on the vue?
本文介绍了如何在Vue上循环获取月份矩js?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有问题
查看此内容: https://codepen.io/positivethinking639/pen/YzzWyaR ?editors = 1010
如果执行了脚本,则console.log(date)
的结果为
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
为什么结果不匹配?
如果我选择下个月,结果也将不匹配
if I choose next month, the results will also not match
推荐答案
已针对以下变量的循环初始化进行了更新:(var i = 1; i< = totalDay; i ++){ 并让date = moment().month(val.split('-')[1] -1).date(i).format("YYYY-MM-DD")
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")
现在它可以正常工作了
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: https://codepen.io/chansv/pen/dyyXYgQ?编辑者= 1010
这篇关于如何在Vue上循环获取月份矩js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文