vue 显示获取系统当前日期
<template><view>{{result}}</view></template><script>export default {data() {//接收当前时间const currentDate = this.getDate({format: true})//双向绑定return {result: currentDate,};},
·
<template>
<view>{{result}}</view>
</template>
<script>
export default {
data() {
//接收当前时间
const currentDate = this.getDate({
format: true
})
//双向绑定
return {
result: currentDate,
};
},
methods: {
// 获取当前时间
getDate() {
const date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
month = month < 10 ? "0" + month : month; //月小于10,加0
day = day < 10 ? "0" + day : day; //day小于10,加0
return `${year}-${month}-${day}`;
}
}
}
</script>
更多推荐
已为社区贡献2条内容
所有评论(0)