feat: 新增 node-frontend-vue3 示例(Vue 3 + Element Plus,Tengine 托管)
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<template>
|
||||
<el-container class="app">
|
||||
<el-header height="56px" class="header">
|
||||
<span class="logo">node-frontend-vue3</span>
|
||||
<el-menu mode="horizontal" :default-active="$route.path" router :ellipsis="false">
|
||||
<el-menu-item index="/">首页</el-menu-item>
|
||||
<el-menu-item index="/form">表单</el-menu-item>
|
||||
<el-menu-item index="/about">关于</el-menu-item>
|
||||
</el-menu>
|
||||
</el-header>
|
||||
<el-main>
|
||||
<router-view />
|
||||
</el-main>
|
||||
</el-container>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
// Vue 3 单文件组件 + 组合式 API,脚本部分刻意保持最小
|
||||
</script>
|
||||
@@ -0,0 +1,10 @@
|
||||
import { createApp } from 'vue';
|
||||
import ElementPlus from 'element-plus';
|
||||
import 'element-plus/dist/index.css';
|
||||
import './styles.css';
|
||||
|
||||
import App from './App.vue';
|
||||
import router from './router';
|
||||
|
||||
// Vue 3 组合式写法 + Element Plus
|
||||
createApp(App).use(router).use(ElementPlus).mount('#app');
|
||||
@@ -0,0 +1,15 @@
|
||||
import { createRouter, createWebHashHistory } from 'vue-router';
|
||||
import Home from './views/HomeView.vue';
|
||||
|
||||
const routes = [
|
||||
{ path: '/', name: 'home', component: Home },
|
||||
{ path: '/form', name: 'form', component: () => import('./views/FormView.vue') },
|
||||
{ path: '/about', name: 'about', component: () => import('./views/AboutView.vue') },
|
||||
// 前端路由兜底:hash 模式下用不到,Tengine 的 location / 里已经配了 try_files
|
||||
{ path: '/:pathMatch(.*)*', redirect: '/' },
|
||||
];
|
||||
|
||||
export default createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes,
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 24px;
|
||||
background: #fff;
|
||||
border-bottom: 1px solid var(--el-border-color-light);
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<template>
|
||||
<el-card shadow="never">
|
||||
<template #header><span>关于</span></template>
|
||||
<el-descriptions :column="1" border>
|
||||
<el-descriptions-item label="框架">Vue 3.5.45(组合式 API,<script setup>)</el-descriptions-item>
|
||||
<el-descriptions-item label="组件库">Element Plus 2.14.8</el-descriptions-item>
|
||||
<el-descriptions-item label="构建">Vite 7 + @vitejs/plugin-vue 6</el-descriptions-item>
|
||||
<el-descriptions-item label="部署">Tengine 3.1.0(proxy-tengine3 镜像)托管 dist/</el-descriptions-item>
|
||||
<el-descriptions-item label="路由模式">hash(无需服务端 rewrite)</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
// 静态说明页,无逻辑
|
||||
</script>
|
||||
@@ -0,0 +1,55 @@
|
||||
<template>
|
||||
<el-card shadow="never">
|
||||
<template #header><span>Element Plus 表单</span></template>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="名称" prop="name">
|
||||
<el-input v-model="form.name" placeholder="请输入名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="类型" prop="type">
|
||||
<el-select v-model="form.type" placeholder="请选择">
|
||||
<el-option label="前端" value="frontend" />
|
||||
<el-option label="后端" value="backend" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="启用">
|
||||
<el-switch v-model="form.enabled" />
|
||||
</el-form-item>
|
||||
<el-form-item label="日期">
|
||||
<el-date-picker v-model="form.date" type="date" value-format="YYYY-MM-DD" placeholder="选择日期" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="submit">提交</el-button>
|
||||
<el-button @click="reset">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-alert v-if="result" :title="result" type="success" :closable="false" show-icon />
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { reactive, ref } from 'vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
const emptyForm = () => ({ name: '', type: '', enabled: true, date: '' });
|
||||
|
||||
const formRef = ref(null);
|
||||
const form = reactive(emptyForm());
|
||||
const result = ref('');
|
||||
const rules = {
|
||||
name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
|
||||
type: [{ required: true, message: '请选择类型', trigger: 'change' }],
|
||||
};
|
||||
|
||||
function submit() {
|
||||
formRef.value.validate((ok) => {
|
||||
if (!ok) return;
|
||||
result.value = `已提交:${JSON.stringify(form)}`;
|
||||
ElMessage.success('提交成功');
|
||||
});
|
||||
}
|
||||
|
||||
function reset() {
|
||||
formRef.value.resetFields();
|
||||
result.value = '';
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,94 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="8">
|
||||
<el-card shadow="never">
|
||||
<template #header><span>运行时</span></template>
|
||||
<el-descriptions :column="1" border>
|
||||
<el-descriptions-item label="Vue">{{ vueVersion }}</el-descriptions-item>
|
||||
<el-descriptions-item label="Element Plus">2.14.8</el-descriptions-item>
|
||||
<el-descriptions-item label="路由">createWebHashHistory</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-card shadow="never">
|
||||
<template #header><span>计数器(ref)</span></template>
|
||||
<el-statistic :value="count" title="当前值" />
|
||||
<div style="margin-top: 16px">
|
||||
<el-button size="small" @click="count -= 1">-1</el-button>
|
||||
<el-button size="small" type="primary" @click="count += 1">+1</el-button>
|
||||
<el-button size="small" @click="count = 0">重置</el-button>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-card shadow="never">
|
||||
<template #header><span>当前时间</span></template>
|
||||
<p class="clock">{{ clock }}</p>
|
||||
<el-tag type="success" size="small">前端本地时间,不请求后端</el-tag>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-card shadow="never" style="margin-top: 16px">
|
||||
<template #header><span>Element Plus 组件一览</span></template>
|
||||
<el-space wrap>
|
||||
<el-button>默认</el-button>
|
||||
<el-button type="primary">主要</el-button>
|
||||
<el-button type="success">成功</el-button>
|
||||
<el-tag>标签</el-tag>
|
||||
<el-tag type="info" effect="plain">描边</el-tag>
|
||||
<el-switch v-model="enabled" />
|
||||
<el-rate v-model="rate" />
|
||||
<el-progress :percentage="percent" style="width: 200px" />
|
||||
</el-space>
|
||||
<el-divider />
|
||||
<el-input v-model="keyword" placeholder="输入关键字过滤,纯前端" clearable style="max-width: 320px" />
|
||||
<el-alert
|
||||
v-if="keyword"
|
||||
style="margin-top: 12px"
|
||||
:title="`已输入:${keyword}`"
|
||||
type="info"
|
||||
:closable="false"
|
||||
show-icon
|
||||
/>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onBeforeUnmount, onMounted, ref, version as vueVersionValue } from 'vue';
|
||||
|
||||
// 纯前端展示:所有数据都在浏览器里产生,不调用任何后端接口
|
||||
const vueVersion = vueVersionValue;
|
||||
const count = ref(0);
|
||||
const clock = ref(format(new Date()));
|
||||
const enabled = ref(true);
|
||||
const rate = ref(4);
|
||||
const percent = ref(60);
|
||||
const keyword = ref('');
|
||||
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>
|
||||
|
||||
<style scoped>
|
||||
.clock {
|
||||
margin: 0 0 12px;
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user