具有类似状态:
this.$store.state.fromDate
我想定义一个这样的变量:
var newFrom = this.$store.state.fromDate.subtract(1, 'days');
无需修改this.$store.state.fromDate
有可能吗?
答案 0 :(得分:2)
您可以clone时刻日期:
// First, clone the moment date object
var newFrom = this.$store.state.fromDate.clone();
// Then, subtract
newFrom.subtract(1, 'days');
这不会减去this.$store.state.fromDate
,而是减去newFrom
或者,在一行中:
var newFrom = this.$store.state.fromDate.clone().subtract(1, 'days');