1.下载
npm install moment --save
2.使用
import moment from 'dayjs';
console.log("1", moment(new Date()).format("YYYY-MM-DD"));
console.log("2", moment(new Date()).add(1, 'days').format("YYYY-MM-DD"));
<template>
<div>
<p>{{ formattedDate }}</p>
</div>
</template>
<script>
import moment from 'moment';
export default {
data() {
return {
date: '2022-01-01',
formattedDate: ''
};
},
mounted() {
this.formattedDate = moment(this.date).format('YYYY-MM-DD');
}
};
</script>