console
new Vue({
el: "#example",
filters: {
formatTimestampToDate(val) {
let temp = new Date(val)
return `${temp.getFullYear()}-${temp.getMonth()+1}-${temp.getDate()} 星期${temp.getDay()}`
}
},
data: {
curDay: new Date().getTime(),
count: 0
},
computed: {
day() {
return this.curDay + (this.count * 24 * 3600 * 1000)
}
},
methods: {
addOneDay() {
this.count++
}
},
watch: {
day: function(newValue, oldValue) {
console.log("this.day === newValue",this.day === newValue)
console.log(`newValue:${newValue},oldValue:${oldValue}`)
}
},
filters: {
formatTimestampToDate(val) {
let temp = new Date(val)
return `${temp.getFullYear()}-${temp.getMonth()+1}-${temp.getDate()} 星期${temp.getDay()}`
}
},
template: `<div>
<div>日期:{{ day | formatTimestampToDate }}</div>
<button type="button" @click="addOneDay">add one day</button>
</div>
`
})
<div id="example"></div>