vue3-项目快速搭建和初始化

news/2024/7/10 0:47:49 标签: 前端, vue

环境安装

npm安装

Node.js各版本:Previous Releases | Node.js (nodejs.org)

Linux

  1. 从官网下载最新版,文件名中是带了linux字样的,如node-v16.20.0-linux-x64.tar.xz

  2. 解压:如果是tar.xz文件,则先用xz -d node-xxxxx.tar.xz现将tar.xz解压为tar包,然后再tar -xvf node-xxx.tar解压;如果是tar.gz文件,则直接tar -zxvf node-xxx.tar.gz解压

  3. 将解压目录移动到/usr/local/:mv node-v16.20.0-linux-x64 /usr/local/node

  4. 创建软链接:ln -s /usr/local/node/bin/node /usr/bin/node

  5. 创建软链接:ln -s /usr/local/node/bin/npm /usr/bin/npm

  6. 查看命令的版本:npm -v;node -v

Windows

下载安装node-vxx.x.x-x64.msi

常用配置

设置源

npm config set registry xxxxx   
# npm config set registry=http://registry.npm.taobao.org

设置默认目录

# Linux
npm config set prefix "/usr/local/node/global"
npm config set cache "/usr/local/node/cache"

# Windows
npm config set prefix "D:\nodejs\node_global"
npm config set cache "D:\nodejs\node_cache"

安装前端构建工具

vuecli_53">vue-cli脚手架

npm install -g @vue/cli

vite

npm install -g vue@latest 
npm install -g webpack 
npm install -g webpack-cli 
npm install -g vite 

安装基本模块

npm install -g element-plus
npm install -g axios
npm install -g vue-router
npm install -g vuex

创建和启动项目

vuecli_83">vue-cli

vue create 项目名称
cd 项目名称
npm install              # 安装模块
npm run serve            # 启动运行

vite

npm init vite-app 项目名称
cd 项目名称
npm install
npm run dev

具体命令,详见vite.config.js配置文件

基本代码框架

引用elementPlus

main.js

// 导入element-plus
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

// icon使用
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 使用element-plus
app.use(ElementPlus)

vue_137">页面vue框架

vue_139">App.vue

vue"><template>
    <RouterView />
</template>
<script>
export default {
 
}
</script>

vue_152">MainView.vue

src/views/MainView.vue

vue"><template>
  <el-container class="layout-container-demo" >
    <el-aside width="200px" class="aside">   
      <el-scrollbar>
        <h2 style="margin-top:5px;text-align:center;font-weight:bold">C I S P</h2>
        <el-menu :default-openeds="['1']" :router="true">
          <el-menu-item index="/">
            <el-icon><House /></el-icon>
            <span>首页</span>
          </el-menu-item>
        </el-menu>
      </el-scrollbar>
    </el-aside>
    <el-container>
      <el-header>
        <div class="toolbar">
          <el-dropdown>
            <el-icon ><setting /></el-icon>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item><el-button link @click="userLogout">LogOut</el-button></el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
          <span>  James </span>
        </div>
      </el-header>

      <el-main class="middle">
          <RouterView />
      </el-main>
    </el-container>
  </el-container>
</template>

vue_195">Login.vue

src/views/Login.vue

vue"><template>
    <div style="display: flex;justify-content: center;margin-top: 150px">
      <el-card style="width: 500px">
        <div class="clearfix" style="text-align:center">
          <h2>用户登录</h2>
        </div>
        <table style="margin-top:40px;width:100%">
          <tr>
            <td>用户</td>
            <td>
                <el-input v-model="user.username" placeholder="请输入用户名"></el-input>
            </td>
          </tr>
          <tr>
            <td>密码</td>
            <td>
                <el-input type="password" v-model="user.password" placeholder="请输入密码" @keydown.enter="doLogin"></el-input>
            </td>
          </tr>
          <tr>
            <td colspan="2">
              <el-button style="width: 50%;margin-left:25%;margin-top:20px" type="primary" @click="doLogin">登录</el-button>
            </td>
          </tr>
        </table>
      </el-card>
    </div>
  </div>
</template>

关于登录,可详见本人《vue3-简单登录认证前端实现样例-CSDN博客》一文。

路由设置

src/router/index.js

import { createRouter, createWebHistory } from 'vue-router'
import MainView from '../views/MainView.vue'
import LoginView from '../views/LoginView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'Home',
      component: MainView
    },
    {
    path: '/aaa',
      name: 'aaa',
      component: MainView,
      children:[
        {
          path: 'aaa/bbb',
          name: 'aaa_bbb',
          component: () => import('@/components/xxxx.vue'),
          meta:{
          }
        }
      ]
    },
    {
      path: '/login',
      name: 'Login',
      component: LoginView,
      meta:{title:"登录"}
    },
    {
        path: '/:pathMatch(.*)*',
        name: 'NoFound',
        component: () => import('@/components/404.vue'),
        meta:{title:"404"}
    },
  ]
})

关于多级路由设置,详见本人《vue3-多级路由实现登录页面与业务功能页面分离_扬雨于今的博客-CSDN博客》


http://www.niftyadmin.cn/n/5060321.html

相关文章

Java 并发编程面试题——BlockingQueue

目录 1.什么是阻塞队列 (BlockingQueue)&#xff1f;2.BlockingQueue 有哪些核心方法&#xff1f;3.BlockingQueue 有哪些常用的实现类&#xff1f;3.1.ArrayBlockingQueue3.2.DelayQueue3.3.LinkedBlockingQueue3.4.PriorityBlockingQueue3.5.SynchronousQueue 4.✨BlockingQu…

聊聊并发编程——并发容器和阻塞队列

目录 一.ConcurrentHashMap 1.为什么要使用ConcurrentHashMap&#xff1f; 2.ConcurrentHashMap的类图 3.ConcurrentHashMap的结构图 二.阻塞队列 Java中的7个阻塞队列 ArrayBlockingQueue&#xff1a;一个由数组结构组成的有界阻塞队列。 LinkedBlockingQueue&#xf…

CSS基础介绍2

CSS使用三种方式 方式1&#xff1a;在标签的style属性上设置CSS样式&#xff08;行内样式&#xff09; <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><title>在标签的style属性上设置CSS样式</title>…

从 低信噪比陆上地震记录 解决办法收集 到 走时层析反演中的折射层析调研

目录 (前言1) 关于背景的回答:(前言2) 现有的降低噪声, 提高信噪比的一些特有方法的论文资料 (传统策略):1. 关于波形反演与走时层析反演2. 折射层析3. 用一个合成数据来解释折射层析反演的思路4. 其他层析反演方法:5. 关于层析反演的一些TIPS (可补充)参考文献: 降噪有关资料参…

高并发时代到底是Go还是Java?

作为一名用过Java和Go开发过微服务架构程序的在校学生的角度思考&#xff0c;本文将从以下几个方便来讲述Go和Java的区别。 前言 小明&#xff1a;听说Go在天然情况下支持并发 小红&#xff1a;我不管Java就是最好的语言 小明&#xff1a;不行&#xff0c;我要学以下神秘的Go…

git创建

问: git remote add origin https://github.com/1109176988/blog.git fatal: not a git repository (or any of the parent directories): .git 回答: 这个错误提示指出当前目录或其父目录中不存在.git文件夹&#xff0c;因此无法执行git相关操作。请确保你是在一个已经初始化…

MyBatis-Plus多数据源——如何在一个项目中使用多个MySQL数据库

前言 MyBatis-Plus (opens new window)&#xff08;简称 MP&#xff09;是一个 MyBatis (opens new window) 的增强工具&#xff0c;在 MyBatis 的基础上只做增强不做改变&#xff0c;为简化开发、提高效率而生。 本系列博客结合实际应用场景&#xff0c;阐述MyBatis-Plus实际…

朴素贝叶斯分类(下):数据挖掘十大算法之一

⭐️⭐️⭐️⭐️⭐️欢迎来到我的博客⭐️⭐️⭐️⭐️⭐️ 🐴作者:秋无之地 🐴简介:CSDN爬虫、后端、大数据领域创作者。目前从事python爬虫、后端和大数据等相关工作,主要擅长领域有:爬虫、后端、大数据开发、数据分析等。 🐴欢迎小伙伴们点赞👍🏻、收藏⭐️、…