使用 vuejs 添加日期
add days to date using vuejs
在数据函数中,我用今天的日期创建了明天的变量,然后我通过附加 1 天来设置它,但我收到了这个错误
data(){
return{
tomorrow: new Date(),
tomorrow.setDate(tomorrow.getDate() + 1),
};
},
error Parsing error: Unexpected token .
数据 属性 是为存储变量而设计的,而不是像您尝试的那样调用函数或添加逻辑。
尝试计算 属性:
computed: {
tomorrow() {
const d = new Date()
d.setDate(d.getDate() + 1)
return d
}
}
然后在你的模板中你可以做 {{ tomorrow }}
或者在你的 vue 组件中 this.tomorrow
在数据函数中,我用今天的日期创建了明天的变量,然后我通过附加 1 天来设置它,但我收到了这个错误
data(){
return{
tomorrow: new Date(),
tomorrow.setDate(tomorrow.getDate() + 1),
};
},
error Parsing error: Unexpected token .
数据 属性 是为存储变量而设计的,而不是像您尝试的那样调用函数或添加逻辑。
尝试计算 属性:
computed: {
tomorrow() {
const d = new Date()
d.setDate(d.getDate() + 1)
return d
}
}
然后在你的模板中你可以做 {{ tomorrow }}
或者在你的 vue 组件中 this.tomorrow