项目启动:搭建Vue 3工程化项目

init 项目

perl 复制代码
nvm install 20
nvm use 20
npm create vite

npm i vue-router@^4.3.0 vuex@^4.1.0

项目结构

arduino 复制代码
├── README.md

├── index.html 入口文件

├── package.json

├── public 资源文件

│ └── favicon.ico

├── src 源码

│ ├── App.vue 单文件组件

│ ├── assets

│ │ └── logo.png

│ ├── components

│ │ └── HelloWorld.vue

│ └── main.js 入口

└── vite.config.js vite工程化配置文件

src 结构规范化

css 复制代码
├── src

│ ├── api 数据请求

│ ├── assets 静态资源

│ ├── components 组件

│ ├── pages 页面

│ ├── router 路由配置

│ ├── store vuex数据

│ └── utils 工具函数

添加一些文件

vbnet 复制代码
router/index.js

import {
createRouter,
createWebHashHistory,
} from 'vue-router'
import Home from '../pages/home.vue'
import About from '../pages/about.vue'

const routes = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/about',
name: 'About',
component: About
}
]
const router = createRouter({
history: createWebHashHistory(),
routes
})
export default router
xml 复制代码
pages/about.vue  

<template>
<h1>这是关于页面</h1>
</template>
xml 复制代码
pages/home.vue  

<template>
<h1>这是首页页面</h1>
</template>
xml 复制代码
App.vue

<script setup>
</script>

<template>
  <div class="container">
    <header>
      <h1>我的 Vue3 应用</h1>
      <nav>
        <router-link to="/">首页</router-link> |
        <router-link to="/about">关于</router-link>
      </nav>
    </header>

    <main>
      <router-view />
    </main>
  </div>
</template>

<style scoped>
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

header {
  text-align: center;
  margin-bottom: 20px;
}

nav {
  margin-top: 10px;
}

main {
  min-height: 300px;
}

footer {
  margin-top: 40px;
  text-align: center;
  color: #888;
}

.logo {
  height: 6em;
  padding: 1.5em;
  will-change: filter;
  transition: filter 300ms;
}
.logo:hover {
  filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vue:hover {
  filter: drop-shadow(0 0 2em #42b883aa);
}
</style>

页面展示

相关推荐
DianSan_ERP17 小时前
电商架构演进:如何在高并发场景下实现多平台API的标准化履约?
运维·前端·网络·安全·架构·自动化
碎_浪20 小时前
给键盘党的英语记忆工具:我做了一款「打字背单词」桌面应用
前端·程序员·ai编程
阿成学长_Cain21 小时前
Linux dirs命令详解|Bash目录堆栈管理快速切换目录实战教程
linux·运维·前端·数据库
多加点辣也没关系21 小时前
JavaScript|第4章:类型转换
开发语言·javascript
yqcoder21 小时前
httpOnly 是什么,又有什么用?
开发语言·前端·javascript
IT_陈寒21 小时前
Java的Stream.parallel()把我CPU跑爆了,这种优化要谨慎
前端·人工智能·后端
小皮虾1 天前
小程序首页性能优化实战:从 4 秒到 1.8 秒
前端·微信小程序
烬羽1 天前
还在手动拼路径、写回调地狱?一文吃透 Node.js 的 path 和 fs
javascript·程序员·node.js
山河木马1 天前
GPU自动处理专题1-裁剪到底在裁什么(裁剪)
前端·webgl·计算机图形学