feat: 新增 node-frontend-vue2 示例(Vue 2.7 + Element UI 2,Tengine 托管)
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<template>
|
||||
<div class="app">
|
||||
<el-container>
|
||||
<el-header height="56px" class="header">
|
||||
<span class="logo">node-frontend-vue2</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>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'App',
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,16 @@
|
||||
import Vue from 'vue';
|
||||
import ElementUI from 'element-ui';
|
||||
import 'element-ui/lib/theme-chalk/index.css';
|
||||
import './styles.css';
|
||||
|
||||
import App from './App.vue';
|
||||
import router from './router';
|
||||
|
||||
// Vue 2.7 内置组合式 API,但示例保持 Vue 2 选项式写法,贴近 Element UI 2 的文档
|
||||
Vue.use(ElementUI);
|
||||
Vue.config.productionTip = false;
|
||||
|
||||
new Vue({
|
||||
router,
|
||||
render: (h) => h(App),
|
||||
}).$mount('#app');
|
||||
@@ -0,0 +1,18 @@
|
||||
import Vue from 'vue';
|
||||
import VueRouter from 'vue-router';
|
||||
import Home from './views/Home.vue';
|
||||
|
||||
Vue.use(VueRouter);
|
||||
|
||||
const routes = [
|
||||
{ path: '/', name: 'home', component: Home },
|
||||
{ path: '/form', name: 'form', component: () => import('./views/Form.vue') },
|
||||
{ path: '/about', name: 'about', component: () => import('./views/About.vue') },
|
||||
// 前端路由兜底:放在 Tengine 上时,需要 location / 里 try_files $uri $uri/ /index.html
|
||||
{ path: '*', redirect: '/' },
|
||||
];
|
||||
|
||||
export default new VueRouter({
|
||||
mode: 'hash',
|
||||
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 #ebeef5;
|
||||
}
|
||||
|
||||
.logo {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #409eff;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<template>
|
||||
<el-card shadow="never">
|
||||
<div slot="header"><span>关于</span></div>
|
||||
<el-descriptions :column="1" border>
|
||||
<el-descriptions-item label="框架">Vue 2.7.16(选项式 API)</el-descriptions-item>
|
||||
<el-descriptions-item label="组件库">Element UI 2.15.14</el-descriptions-item>
|
||||
<el-descriptions-item label="构建">Vite 7 + @vitejs/plugin-vue2</el-descriptions-item>
|
||||
<el-descriptions-item label="部署">Tengine 3.1.0(proxy-tengine3 镜像)托管 dist/</el-descriptions-item>
|
||||
<el-descriptions-item label="路由模式">hash(无需服务端 rewrite;换成 history 需要 try_files 兜底)</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'About',
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,58 @@
|
||||
<template>
|
||||
<el-card shadow="never">
|
||||
<div slot="header"><span>Element UI 2 常用组件</span></div>
|
||||
<el-form ref="form" :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>
|
||||
const emptyForm = () => ({ name: '', type: '', enabled: true, date: '' });
|
||||
|
||||
export default {
|
||||
name: 'Form',
|
||||
data() {
|
||||
return {
|
||||
form: emptyForm(),
|
||||
result: '',
|
||||
rules: {
|
||||
name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
|
||||
type: [{ required: true, message: '请选择类型', trigger: 'change' }],
|
||||
},
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
submit() {
|
||||
this.$refs.form.validate((ok) => {
|
||||
if (!ok) return;
|
||||
this.result = `已提交:${JSON.stringify(this.form)}`;
|
||||
this.$message.success('提交成功');
|
||||
});
|
||||
},
|
||||
reset() {
|
||||
this.$refs.form.resetFields();
|
||||
this.result = '';
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,109 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="8">
|
||||
<el-card shadow="never">
|
||||
<div slot="header"><span>运行时</span></div>
|
||||
<el-descriptions :column="1" border>
|
||||
<el-descriptions-item label="Vue">{{ vueVersion }}</el-descriptions-item>
|
||||
<el-descriptions-item label="Element UI">{{ elementVersion }}</el-descriptions-item>
|
||||
<el-descriptions-item label="路由模式">{{ routerMode }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-card shadow="never">
|
||||
<div slot="header">
|
||||
<span>计数器</span>
|
||||
</div>
|
||||
<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">
|
||||
<div slot="header"><span>当前时间</span></div>
|
||||
<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">
|
||||
<div slot="header"><span>Element UI 2 组件一览</span></div>
|
||||
<el-space wrap>
|
||||
<el-button>默认</el-button>
|
||||
<el-button type="primary">主要</el-button>
|
||||
<el-button type="success">成功</el-button>
|
||||
<el-button type="warning">警告</el-button>
|
||||
<el-button type="danger">危险</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>
|
||||
import Vue from 'vue';
|
||||
import ElementUI from 'element-ui';
|
||||
|
||||
// 纯前端展示:所有数据都在浏览器里产生,不调用任何后端接口
|
||||
export default {
|
||||
name: 'Home',
|
||||
data() {
|
||||
return {
|
||||
vueVersion: Vue.version,
|
||||
elementVersion: ElementUI.version,
|
||||
routerMode: this.$router.mode,
|
||||
count: 0,
|
||||
clock: this.format(new Date()),
|
||||
enabled: true,
|
||||
rate: 4,
|
||||
percent: 60,
|
||||
keyword: '',
|
||||
timer: null,
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.timer = setInterval(() => {
|
||||
this.clock = this.format(new Date());
|
||||
}, 1000);
|
||||
},
|
||||
beforeDestroy() {
|
||||
clearInterval(this.timer);
|
||||
},
|
||||
methods: {
|
||||
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())}`;
|
||||
},
|
||||
},
|
||||
};
|
||||
</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