首页 > 其他分享 >vite+vue3+ts+ element-plus 5分钟快速搭建高端大气上档次的企业级网站前端框架

vite+vue3+ts+ element-plus 5分钟快速搭建高端大气上档次的企业级网站前端框架

时间:2024-02-19 14:01:09浏览次数:32  
标签:index vue ts 企业级 plus router import element

原文地址:https://mp.weixin.qq.com/s/BANsRtNn5u-4521nFwF3FA

一、安装需要的包:

1、 element-plus 

安装命令:

npm install element-plus --save

 

 

2、vue-router

安装命令:

npm install vue-router --save

 

 

安装完成后,需要到main.ts注册:

import { createApp } from 'vue' import App from './App.vue' import ElementPlus from 'element-plus' import 'element-plus/dist/index.css' import router from './router'
const app = createApp(App) app.use(ElementPlus) app.use(router) app.mount('#app')

 

二、基本页面:

如图,在components目录下新建几个页面和导航对应的组件:

首页 index.vue

产品介绍 Product.vue

关于我们 AboutUs.vue

联系我们 CallMe.vue

导航菜单 Nav.vue

 

这几个页面的代码如下:

翻译

搜索

复制

<iframe></iframe>

一、安装需要的包:

1、 element-plus 

安装命令:

npm install element-plus --save

2、vue-router

安装命令:

npm install vue-router --save

 

安装完成后,需要到main.ts注册:

import ElementPlus from 'element-plus'

import 'element-plus/dist/index.css'

import router from './router'

createApp(App).use(router).use(ElementPlus).mount('#app')

 

二、基本页面:

如图,在components目录下新建几个页面和导航对应的组件:

首页 index.vue

产品介绍 Product.vue

关于我们 AboutUs.vue

联系我们 CallMe.vue

导航菜单 Nav.vue

图片

 

这几个页面的代码如下:

首页 index.vue:

<script setup lang="ts"></script><template><div id="content">    <h2>网站首页</h2></div></template><style scoped>#content{    width: 100%;    height: 500px;
}</style>

 

产品介绍 Product.vue:

<script setup lang="ts"></script><template><div id="content">    <h2>产品介绍</h2></div></template><style scoped>#content{    width: 100%;    height: 500px;
}</style>

关于我们 AboutUs.vue:

<script setup lang="ts"></script><template><div id="content">    <h2>关于我们</h2></div></template><style scoped>#content{    width: 100%;    height: 500px;
}</style>

联系我们 CallMe.vue:

<script setup lang="ts"></script><template><div id="content">    <h2>关于我们</h2></div></template><style scoped>#content{    width: 100%;    height: 500px;
}</style>

 

导航菜单 Nav.vue 暂时留白不写代码,待会建好路由再来写。

 

 

三、路由设置:

新建一个文件夹叫router,文件夹里面新建一个文件叫index.ts:

图片

路由文件里面的代码如下:

import { createRouter,createWebHistory,RouteRecordRaw } from "vue-router";
import index from "../components/index.vue";import ProductVue from "../components/Product.vue";import AboutUsVue from "../components/AboutUs.vue";import CallMeVue from "../components/CallMe.vue";
//创建路由数据集合 --arrayconst routes:Array<RouteRecordRaw>=[ { path:'/', name:'index', component:index, }, { path:'/product', name:'product', component:ProductVue,
}, { path:'/about', name:'about', component:AboutUsVue,
}, { path:'/call', name:'call', component:CallMeVue,
}]
//创建一个vue-router的对象const router = createRouter({ history:createWebHistory(), routes,})
//暴露export default router

 

然后编辑导航菜单Nav.vue,代码如下:

<script lang="ts" setup></script>
<template> <div id="out">
<div id="in"> <el-menu class="el-menu-demo" mode="horizontal"> <el-menu-item index="1"><router-link :to="{name:'index'}">首页</router-link></el-menu-item> <el-menu-item index="2"><router-link :to="{name:'product'}">产品介绍</router-link></el-menu-item> <el-menu-item index="3"><router-link :to="{name:'about'}">关于我们</router-link></el-menu-item> <el-menu-item index="4"><router-link :to="{name:'call'}">联系我们</router-link></el-menu-item> </el-menu> </div> </div></template>
<style scoped>#out{ width: 100%; margin: 10 auto;}
#in{ width: 1200px; height: 100px; margin: 0 auto;}</style>

 

四、编辑app.vue文件:

<script setup lang="ts">import Nav from './components/Nav.vue'</script>
<template> <Nav></Nav> <div> <a href="https://vitejs.dev" target="_blank"> <img src="/vite.svg" class="logo" alt="Vite logo" /> </a> <a href="https://vuejs.org/" target="_blank"> <img src="./assets/vue.svg" class="logo vue" alt="Vue logo" /> </a> </div> <router-view></router-view></template>
<style scoped></style>

 

五、服务器配置:

打开vite.config.ts文件,添加server代码,让本地所有ip都可以访问:

import { defineConfig } from 'vite'import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/export default defineConfig({ plugins: [vue()], server:{ host:'0.0.0.0', port:80, open:true }})

 

最后,在vscode终端运行npm run dev 即可看到效果:

http://localhost/

图片

 

http://localhost/product

图片

 

 

http://localhost/about

图片

 

http://localhost/call

图片

 

瞧,高端不,大气不,上档次不?

还在犹豫什么,赶紧动手搭建起来吧,需要源码可关注微信公众号,后台回复“前端”获取。

标签:index,vue,ts,企业级,plus,router,import,element
From: https://www.cnblogs.com/lizhigang/p/18020940

相关文章

  • Vite+Vue3+TS创建前端页面,收费教程都没有这么详细
    原文地址:https://mp.weixin.qq.com/s/HqLgf2TCVqnndSxJw_1RTQ一、准备工作在学习之前,需要安装两个工具,一个是IDE,一个是Node.js:VsCode: https://code.visualstudio.com/DownloadNode.js: http://nodejs.cn/download/安装过程略,安装好之后,为了在vscode中能智能提示和运行,......
  • RevBits Email Security - Endpoint Agent分析(EDR+API集成)
    https://revbits.com/pdf/RevBits_Email_Security_Product_Brief_Securing_Email_Inboxes.pdf 邮件安全检测场景? 根据文档内容,RevBits邮件安全提供以下邮件安全检测场景:终端邮件安全代理软件直接部署在用户终端,可以在邮件进入用户收件箱时进行深度分析,检测和......
  • echarts自适应问题,echarts中怎么改变字体单位实现自适应
    参考文档:https://blog.csdn.net/MFWSCQ/article/details/102522944最初想着怎么给echarts设置vw单位或者rem,echart中怎么把legend的单位设置为vw或者rem来使表格自适应,后面发现行不通。项目中使用px-to-vw包,将所有px转为对应的vw,所有可以根据相同比例进行缩放,做到自适应效果。但......
  • ts接口03
    //接口对对象的形状进行描述可以理解为一种约束//?表示为可选属性,表示可有可无//[prop:string]代表任意属性,当不确定属性名的时候,属性类型,可以使用,但是要注意的是,一旦确定了不是any类型,而是string,number,Boolean之类的,其他的类型也会变成他的子集//[prop:string]中如......
  • v-if后的echarts显示已有dom解决方法
    控制台报错:Thereisachartinstancealreadyinitializedonthedom. 核心思路:先判断dom是否存在,如存在就调用销毁方法,再初始化正常操作。echarts内:if(this.myChart!=null&&this.myChart!=""&&this.myChart!=undefined......
  • ts基础类型02
    类型声明letnum:number=11num=10functiona(aaa:string){  console.log(aaa)}a('111')//类型声明,指定ts变量(参数,形参)的类型ts编译器,自动检测//类型声明给变量设置了类型后,该变量只能储存对应类型的值,如下letflag:boolean=trueflag=false......
  • ts编译01
    认知 TS:TS是JS的超集安装TSnpmi-gtypescript检测安装是否成功tsc-v测试(()=>{functionsayHi(str:string){returnstr}sayHi('ts')})()手动编译tsc./文件名 自动编译tsc--init自动编译后,出现一个tsconfig.j......
  • netstat和lsof两个Linux命令查看端口的区别
    一、netstat命令介绍netstat命令是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表、实际的网络连接以及每一个网络接口设备的状态信息netstat用来查看系统当前系统网络状态信息,包括端口,连接情况等,常用方式如下:netstat-atunlp,各参数含义如下:•-t:指明显示TCP端口•-......
  • 记一次centos7.9崩溃恢复操作(limits.conf配置失误),救援模式
    引起故障的原因:调整了操作系统的内核参数文件limits.conf,* softnproc131072* hardnproc131072* softnofile65536* hardnofile131072 以上的参数都扩大了10倍,ssh登录主机就开始异常了,连上去后就直接断开了,表象就是无法新建ssh会话连接,当前的用户有sudo免密操......
  • 149. Max Points on a Line
    149.MaxPointsonaLineGivenanarrayof points where points[i]=[xi,yi] representsapointonthe X-Y plane,return themaximumnumberofpointsthatlieonthesamestraightline.Example1:Input:points=[[1,1],[2,2],[3,3]]Output:3E......