
获得徽章 15
赞了这篇文章
获取当前年份前连续5年的方法
calculateAvailableYears() {
const currentYear = dayjs().year();
this.availableYears = Array.from(
{ length: 5 },
(_, index) => currentYear - index
);
}
输出 [2024, 2023, 2022, 2021, 2020]
calculateAvailableYears() {
const currentYear = dayjs().year();
this.availableYears = Array.from(
{ length: 5 },
(_, index) => currentYear - index
);
}
输出 [2024, 2023, 2022, 2021, 2020]
展开
4
点赞
赞了这篇文章
console.log(JSON.stringify(需要打印的数据, null, 2));
null 是可选参数,用于控制如何处理对象的属性值,通常用 null 表示不进行特殊处理。
2 是一个可选的参数,用于指定缩进空格的数量,使输出的 JSON 字符串更易读。
举例
var data = { "name": "John", "age": 30, "city": "New York" };
console.log(JSON.stringify(data, null, 2));
{
"name": "John",
"age": 30,
"city": "New York"
}
null 是可选参数,用于控制如何处理对象的属性值,通常用 null 表示不进行特殊处理。
2 是一个可选的参数,用于指定缩进空格的数量,使输出的 JSON 字符串更易读。
举例
var data = { "name": "John", "age": 30, "city": "New York" };
console.log(JSON.stringify(data, null, 2));
{
"name": "John",
"age": 30,
"city": "New York"
}
展开
4
1
赞了这篇沸点
赞了这篇沸点
赞了这篇沸点