diff --git a/src/mock/index.ts b/src/mock/index.ts new file mode 100644 index 0000000..0c3342d --- /dev/null +++ b/src/mock/index.ts @@ -0,0 +1,6 @@ +import formattedDate from './time' + +export const mockData = { + time: formattedDate, + message: 'Hello, this is mock data!', +} diff --git a/src/mock/time.ts b/src/mock/time.ts new file mode 100644 index 0000000..14ac56f --- /dev/null +++ b/src/mock/time.ts @@ -0,0 +1,13 @@ +// 1. 获取当前设备时间 +const now = new Date() + +// 2. 提取年、月、日 +const year = now.getFullYear() +const month = String(now.getMonth() + 1).padStart(2, '0') +const day = String(now.getDate()).padStart(2, '0') + +// 3. 拼接成指定格式 +const formattedDate = `${year}年${month}月${day}日` + +// console.log(formattedDate) // 输出示例:2026年8月25日 +export default formattedDate diff --git a/src/pages/home/index.vue b/src/pages/home/index.vue index 0394bf9..0135cd5 100644 --- a/src/pages/home/index.vue +++ b/src/pages/home/index.vue @@ -1,4 +1,6 @@