Skip to content

data中使用默认日期

vue
<script>
export default {
    data() {
        const d = new Date()
        const year = d.getFullYear()
        let month = d.getMonth() + 1
        month = month < 10 ? `0${month}` : month
        const date = d.getDate()
        return {
            date: `${year}-${month}-${date}`,
        }
    },
    methods: {},
}
</script>
<script>
export default {
    data() {
        const d = new Date()
        const year = d.getFullYear()
        let month = d.getMonth() + 1
        month = month < 10 ? `0${month}` : month
        const date = d.getDate()
        return {
            date: `${year}-${month}-${date}`,
        }
    },
    methods: {},
}
</script>

如有转载或 CV 的请标注本站原文地址