feat 创建源数据文件

This commit is contained in:
Ironsp
2026-08-25 09:50:36 +08:00
parent 6d5cb0fdc3
commit 65abf0216d
3 changed files with 23 additions and 0 deletions

6
src/mock/index.ts Normal file
View File

@@ -0,0 +1,6 @@
import formattedDate from './time'
export const mockData = {
time: formattedDate,
message: 'Hello, this is mock data!',
}

13
src/mock/time.ts Normal file
View File

@@ -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

View File

@@ -1,4 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { mockData } from '@/mock/index'
definePage({ definePage({
layout: false, layout: false,
}) })
@@ -6,6 +8,8 @@ definePage({
<template> <template>
<view>首页</view> <view>首页</view>
<view>消息:{{ mockData.message }}</view>
<view>时间:{{ mockData.time }}</view>
</template> </template>
<style></style> <style></style>