feat: 新增 node-frontend-vite5 示例(Vite 5 + Vue 3,Tengine 托管)

This commit is contained in:
2026-11-15 11:53:02 +08:00
parent 92a57d99a0
commit 90c3334368
15 changed files with 432 additions and 0 deletions
+74
View File
@@ -0,0 +1,74 @@
<template>
<div class="app">
<header class="header">
<span class="logo">node-frontend-vite5</span>
<span class="tag">Vite 5 + Vue 3</span>
</header>
<main class="main">
<div class="grid">
<section class="card">
<h3 class="card-title">构建信息</h3>
<table class="kv">
<tbody>
<tr><th>Vite</th><td>{{ viteVersion }}</td></tr>
<tr><th>Vue</th><td>{{ vueVersion }}</td></tr>
<tr><th>Node 要求</th><td>Vite 5 支持 Node 18+(镜像用 22)</td></tr>
</tbody>
</table>
</section>
<section class="card">
<h3 class="card-title">计数器</h3>
<p class="big">{{ count }}</p>
<button class="btn" @click="count -= 1">-1</button>
<button class="btn primary" @click="count += 1">+1</button>
<button class="btn" @click="count = 0">重置</button>
</section>
<section class="card">
<h3 class="card-title">当前时间</h3>
<p class="big small">{{ clock }}</p>
<span class="hint">前端本地时间,不请求后端</span>
</section>
</div>
<section class="card">
<h3 class="card-title">构建环境变量(import.meta.env)</h3>
<table class="kv">
<tbody>
<tr><th>MODE</th><td>{{ env.MODE }}</td></tr>
<tr><th>PROD</th><td>{{ env.PROD }}</td></tr>
<tr><th>BASE_URL</th><td>{{ env.BASE_URL }}</td></tr>
</tbody>
</table>
</section>
</main>
</div>
</template>
<script setup>
import { onBeforeUnmount, onMounted, ref } from 'vue';
import { version as vueVersionValue } from 'vue';
// Vite 在构建时把 import.meta.env 静态替换成字面量,生产包里不会泄露其它环境变量
const env = import.meta.env;
const viteVersion = `5.4.21`;
const vueVersion = vueVersionValue;
const count = ref(0);
const clock = ref(format(new Date()));
let timer = null;
function format(d) {
const p = (n) => String(n).padStart(2, '0');
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
}
onMounted(() => {
timer = setInterval(() => {
clock.value = format(new Date());
}, 1000);
});
onBeforeUnmount(() => clearInterval(timer));
</script>
+5
View File
@@ -0,0 +1,5 @@
import { createApp } from 'vue';
import App from './App.vue';
import './styles.css';
createApp(App).mount('#app');
+115
View File
@@ -0,0 +1,115 @@
* {
box-sizing: border-box;
}
html,
body,
#app {
height: 100%;
margin: 0;
}
body {
font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
color: #303133;
background: #f5f7fa;
}
.header {
display: flex;
align-items: center;
gap: 12px;
height: 56px;
padding: 0 20px;
background: #fff;
border-bottom: 1px solid #ebeef5;
}
.logo {
font-size: 18px;
font-weight: 600;
color: #42b883;
}
.tag {
padding: 2px 8px;
border-radius: 10px;
background: #f0f9eb;
color: #67c23a;
font-size: 12px;
}
.main {
padding: 20px;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
gap: 16px;
}
.card {
padding: 20px;
background: #fff;
border: 1px solid #ebeef5;
border-radius: 4px;
}
.card + .card {
margin-top: 16px;
}
.card-title {
margin: 0 0 16px;
font-size: 16px;
font-weight: 600;
}
.kv {
width: 100%;
border-collapse: collapse;
}
.kv th,
.kv td {
padding: 6px 12px;
border: 1px solid #ebeef5;
text-align: left;
}
.kv th {
width: 40%;
background: #fafafa;
}
.big {
margin: 0 0 12px;
font-size: 28px;
font-weight: 600;
font-variant-numeric: tabular-nums;
}
.big.small {
font-size: 20px;
}
.btn {
margin-right: 8px;
padding: 6px 14px;
border: 1px solid #dcdfe6;
border-radius: 4px;
background: #fff;
cursor: pointer;
}
.btn.primary {
color: #fff;
border-color: #42b883;
background: #42b883;
}
.hint {
color: #909399;
font-size: 12px;
}