<div id='app'>
<p>当前时间为:{{time|formatDate('xxxx-mm-dd')}}</p>
</div>
<script src='js/vue.js'></script>
<script>
Vue.filter("formatDate", function (value, str) {
let dt = new Date(value)
let year = (dt.getFullYear() + "").padStart(2, "0")
let month = (dt.getMonth() + 1 + "").padStart(2, "0")
let date = (dt.getDate() + "").padStart(2, "0")
let hours = (dt.getHours() + "").padStart(2, "0")
let minutes = (dt.getMinutes() + "").padStart(2, "0")
let seconds = (dt.getSeconds() + "").padStart(2, "0")
if (str == "xxxx-mm-dd") {
return `${year}-${month}-${date}`
} else {
return `${year}-${month}-${date}-${hours}:${minutes}:${seconds}`
}
})
let vm = new Vue({
el: '#app',
data: {
time: Date.now()
}
})
</script>
07-20
113
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-16