feat 创建源数据文件
This commit is contained in:
6
src/mock/index.ts
Normal file
6
src/mock/index.ts
Normal 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
13
src/mock/time.ts
Normal 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
|
||||
@@ -1,4 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { mockData } from '@/mock/index'
|
||||
|
||||
definePage({
|
||||
layout: false,
|
||||
})
|
||||
@@ -6,6 +8,8 @@ definePage({
|
||||
|
||||
<template>
|
||||
<view>首页</view>
|
||||
<view>消息:{{ mockData.message }}</view>
|
||||
<view>时间:{{ mockData.time }}</view>
|
||||
</template>
|
||||
|
||||
<style></style>
|
||||
|
||||
Reference in New Issue
Block a user