Vue项目搭建过程

Vue项目搭建过程

1、安装NodeJs

1.1 下载安装包

http://nodejs.cn/download/ 上下载64位安装包,然后进行安装,和普通软件的安装一样。

C:\Users\Administrator>node -v
v16.13.1C:\Users\Administrator>npm -v
8.5.5
1.2 安装cnpm
# 安装cnpm
C:\Users\Administrator>npm install cnpm -gadded 171 packages, removed 378 packages, and changed 281 packages in 18s11 packages are looking for fundingrun `npm fund` for details
npm notice
npm notice New minor version of npm available! 8.5.5 -> 8.15.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.15.1
npm notice Run npm install -g npm@8.15.1 to update!
npm notice
# 查看cnpm的版本
C:\Users\Administrator>cnpm -vcnpm@8.2.0 (C:\Users\Administrator\AppData\Roaming\npm\node_modules\cnpm\lib\parse_argv.js)
npm@8.15.1 (C:\Users\Administrator\AppData\Roaming\npm\node_modules\cnpm\node_modules\npm\index.js)
node@16.13.1 (C:\zsxsoftware\nodejs\node.exe)
npminstall@6.5.0 (C:\Users\Administrator\AppData\Roaming\npm\node_modules\cnpm\node_modules\npminstall\lib\index.js)
prefix=C:\Users\Administrator\AppData\Roaming\npm
win32 x64 10.0.19042
registry=https://registry.npmmirror.com
1.3 安装 vue-cli
# 安装vue-cli
C:\Users\Administrator>cnpm install vue-cli -g(node:16924) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Downloading vue-cli to C:\Users\Administrator\AppData\Roaming\npm\node_modules\vue-cli_tmp
Copying C:\Users\Administrator\AppData\Roaming\npm\node_modules\vue-cli_tmp\_vue-cli@2.9.6@vue-cli to C:\Users\Administrator\AppData\Roaming\npm\node_modules\vue-cli
Installing vue-cli's dependencies to C:\Users\Administrator\AppData\Roaming\npm\node_modules\vue-cli/node_modules
[1/20] uid@0.0.2 installed at node_modules\_uid@0.0.2@uid
[2/20] commander@^2.9.0 installed at node_modules\_commander@2.20.3@commander
[3/20] semver@^5.1.0 installed at node_modules\_semver@5.7.1@semver
[4/20] coffee-script@1.12.7 installed at node_modules\_coffee-script@1.12.7@coffee-script
[5/20] user-home@^2.0.0 installed at node_modules\_user-home@2.0.0@user-home
[6/20] tildify@^1.2.0 installed at node_modules\_tildify@1.2.0@tildify
[7/20] validate-npm-package-name@^3.0.0 installed at node_modules\_validate-npm-package-name@3.0.0@validate-npm-package-name
[8/20] multimatch@^2.1.0 installed at node_modules\_multimatch@2.1.0@multimatch
[9/20] minimatch@^3.0.0 installed at node_modules\_minimatch@3.1.2@minimatch
[10/20] read-metadata@^1.0.0 installed at node_modules\_read-metadata@1.0.0@read-metadata
[11/20] chalk@^2.1.0 installed at node_modules\_chalk@2.4.2@chalk
[12/20] consolidate@^0.14.0 installed at node_modules\_consolidate@0.14.5@consolidate
[13/20] rimraf@^2.5.0 installed at node_modules\_rimraf@2.7.1@rimraf
[14/20] ora@^1.3.0 installed at node_modules\_ora@1.4.0@ora
[15/20] metalsmith@^2.1.0 installed at node_modules\_metalsmith@2.5.0@metalsmith
[16/20] request@^2.67.0 installed at node_modules\_request@2.88.2@request
[17/20] handlebars@^4.0.5 installed at node_modules\_handlebars@4.7.7@handlebars
[18/20] download-git-repo@^1.0.1 installed at node_modules\_download-git-repo@1.1.0@download-git-repo
[19/20] async@^2.4.0 installed at node_modules\_async@2.6.4@async
[20/20] inquirer@^6.0.0 installed at node_modules\_inquirer@6.5.2@inquirer
execute post install 1 scripts...
[1/1] scripts.postinstall metalsmith@^2.1.0 run "node metalsmith-migrated-plugins.js", root: "C:\\Users\\Administrator\\AppData\\Roaming\\npm\\node_modules\\vue-cli\\node_modules\\_metalsmith@2.5.0@metalsmith"
[1/1] scripts.postinstall metalsmith@^2.1.0 finished in 106ms
deprecate request@^2.67.0 request has been deprecated, see https://github.com/request/request/issues/3142
deprecate coffee-script@1.12.7 CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
deprecate request@2.88.2 › har-validator@~5.1.3 this library is no longer supported
deprecate request@2.88.2 › uuid@^3.3.2 Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
All packages installed (228 packages installed from npm registry, used 5s(network 5s), speed 1.18MB/s, json 217(1.01MB), tarball 4.64MB, manifests cache hit 0, etag hit 0 / miss 0)
[vue-cli@2.9.6] link C:\Users\Administrator\AppData\Roaming\npm\vue@ -> C:\Users\Administrator\AppData\Roaming\npm\node_modules\vue-cli\bin\vue
[vue-cli@2.9.6] link C:\Users\Administrator\AppData\Roaming\npm\vue-init@ -> C:\Users\Administrator\AppData\Roaming\npm\node_modules\vue-cli\bin\vue-init
[vue-cli@2.9.6] link C:\Users\Administrator\AppData\Roaming\npm\vue-list@ -> C:\Users\Administrator\AppData\Roaming\npm\node_modules\vue-cli\bin\vue-list
1.4 安装webpack
# 安装webpack
C:\Users\Administrator>cnpm install webpack -g(node:13296) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Downloading webpack to C:\Users\Administrator\AppData\Roaming\npm\node_modules\webpack_tmp
Copying C:\Users\Administrator\AppData\Roaming\npm\node_modules\webpack_tmp\_webpack@5.74.0@webpack to C:\Users\Administrator\AppData\Roaming\npm\node_modules\webpack
Installing webpack's dependencies to C:\Users\Administrator\AppData\Roaming\npm\node_modules\webpack/node_modules
[1/24] chrome-trace-event@^1.0.2 installed at node_modules\_chrome-trace-event@1.0.3@chrome-trace-event
[2/24] graceful-fs@^4.2.9 installed at node_modules\_graceful-fs@4.2.10@graceful-fs
[3/24] glob-to-regexp@^0.4.1 installed at node_modules\_glob-to-regexp@0.4.1@glob-to-regexp
[4/24] loader-runner@^4.2.0 installed at node_modules\_loader-runner@4.3.0@loader-runner
[5/24] @types/estree@^0.0.51 installed at node_modules\_@types_estree@0.0.51@@types\estree
[6/24] acorn-import-assertions@^1.7.6 installed at node_modules\_acorn-import-assertions@1.8.0@acorn-import-assertions
[7/24] acorn@^8.7.1 installed at node_modules\_acorn@8.8.0@acorn
[8/24] json-parse-even-better-errors@^2.3.1 installed at node_modules\_json-parse-even-better-errors@2.3.1@json-parse-even-better-errors
[9/24] es-module-lexer@^0.9.0 installed at node_modules\_es-module-lexer@0.9.3@es-module-lexer
[10/24] watchpack@^2.4.0 installed at node_modules\_watchpack@2.4.0@watchpack
[11/24] events@^3.2.0 installed at node_modules\_events@3.3.0@events
[12/24] mime-types@^2.1.27 installed at node_modules\_mime-types@2.1.35@mime-types
[13/24] tapable@^2.1.1 installed at node_modules\_tapable@2.2.1@tapable
[14/24] webpack-sources@^3.2.3 installed at node_modules\_webpack-sources@3.2.3@webpack-sources
[15/24] enhanced-resolve@^5.10.0 installed at node_modules\_enhanced-resolve@5.10.0@enhanced-resolve
[16/24] @types/eslint-scope@^3.7.3 installed at node_modules\_@types_eslint-scope@3.7.4@@types\eslint-scope
[17/24] neo-async@^2.6.2 installed at node_modules\_neo-async@2.6.2@neo-async
[18/24] eslint-scope@5.1.1 installed at node_modules\_eslint-scope@5.1.1@eslint-scope
[19/24] @webassemblyjs/wasm-edit@1.11.1 installed at node_modules\_@webassemblyjs_wasm-edit@1.11.1@@webassemblyjs\wasm-edit
[20/24] @webassemblyjs/ast@1.11.1 installed at node_modules\_@webassemblyjs_ast@1.11.1@@webassemblyjs\ast
[21/24] @webassemblyjs/wasm-parser@1.11.1 installed at node_modules\_@webassemblyjs_wasm-parser@1.11.1@@webassemblyjs\wasm-parser
[22/24] schema-utils@^3.1.0 installed at node_modules\_schema-utils@3.1.1@schema-utils
[23/24] terser-webpack-plugin@^5.1.3 installed at node_modules\_terser-webpack-plugin@5.3.3@terser-webpack-plugin
[24/24] browserslist@^4.14.5 installed at node_modules\_browserslist@4.21.3@browserslist
anti semver @types/eslint-scope@3.7.4 › @types/estree@* delcares @types/estree@*(resolved as 1.0.0) but using ancestor(root package.json)'s dependency @types/estree@^0.0.51(resolved as 0.0.51)
anti semver @types/eslint-scope@3.7.4 › @types/eslint@8.4.5 › @types/estree@* delcares @types/estree@*(resolved as 1.0.0) but using ancestor(root package.json)'s dependency @types/estree@^0.0.51(resolved as 0.0.51)
All packages installed (76 packages installed from npm registry, used 2s(network 2s), speed 2.18MB/s, json 75(1.32MB), tarball 2.31MB, manifests cache hit 0, etag hit 0 / miss 0)
[webpack@5.74.0] link C:\Users\Administrator\AppData\Roaming\npm\webpack@ -> C:\Users\Administrator\AppData\Roaming\npm\node_modules\webpack\bin\webpack.js
# 查看webpack的版本
C:\Users\Administrator>webpack -v
webpack: 5.74.0
webpack-cli: 4.10.0
webpack-dev-server not installed
1.5 安装webpack-cli
# 安装webpack-cli
C:\Users\Administrator>npm install webpack-cli -gadded 117 packages in 6s
# 查看webpack-cli的版本
C:\Users\Administrator>webpack-cli -v
webpack: 5.74.0
webpack-cli: 4.10.0
webpack-dev-server not installed
# 查看模板
C:\Users\Administrator>vue listAvailable official templates:★  browserify - A full-featured Browserify + vueify setup with hot-reload, linting & unit testing.★  browserify-simple - A simple Browserify + vueify setup for quick prototyping.★  pwa - PWA template for vue-cli based on the webpack template★  simple - The simplest possible Vue setup in a single HTML file★  webpack - A full-featured Webpack + vue-loader setup with hot reload, linting, testing & css extraction.★  webpack-simple - A simple Webpack + vue-loader setup for quick prototyping.

2、新建shop-vue项目

使用 webpack 初始化项目:

$ vue init webpack shop-vue? Project name shop-vue
? Project description A Vue.js project
? Author zsx242030 <15110820283@163.com>
? Vue build standalone
? Install vue-router? Yes
? Use ESLint to lint your code? No
? Set up unit tests No
? Setup e2e tests with Nightwatch? No
? Should we run `npm install` for you after the project has been created? (recommended) novue-cli · Generated "shop-vue".# Project initialization finished!
# ========================To get started:cd shop-vuenpm install (or if using yarn: yarn)npm run devDocumentation can be found at https://vuejs-templates.github.io/webpack

生成的项目结构如下:

在这里插入图片描述

然后执行 npm installnpm audit fix 安装一些相关的依赖,会生成 node_modules 目录:

在这里插入图片描述

build:项目构建(webpack)相关代码

config:配置目录,包括端口号等

node_modules :npm加载的项目依赖块

src:这里是我们要开发的目录,基本上要做的事情都在这个目录里。里面包含了几个目录及文件:

assets: 放置一些图片,如logo等

components:该目录里存放的我们的开发文件组件,主要的开发文件都存放在这里了

App.vue:项目入口文件

main.js:项目的核心文件

router:路由配置目录

static:放置一些静态资源文件

.babelrc:用来设置转码的规则和插件的

.editorconfig:用于定义编码样式的文件格式和一组文本编辑器插件组成

.gitignore:这些是一些配置文件,包括语法配置,git配置等

.postcssrc.js:为了进行移动端适配,PostCss 是一个处理 CSS 的处理工具

index.html:首页入口文件

package.json:项目配置文件

README.md:项目的说明文档,markdown 格式

使用 npm run dev 启动项目,访问 http://localhost:8080

在这里插入图片描述

接下来使用开发工具打开项目:

在这里插入图片描述

对代码进行修改:

App.vue 修改为:

<template><div id="app"><router-view/></div>
</template><script>
export default {name: 'App'
}
</script><style>
</style>

main.js 修改为:

import Vue from 'vue'
import App from './App'
import router from './router'Vue.config.productionTip = falsenew Vue({el: '#app',router,components: { App },template: '<App/>'
})

HelloWorld.vue 删除,并且在src下新建 views 文件夹, 在该文件夹下新建 Index.vue,其内容改为:

<template><div class="index"><h1>首页</h1></div>
</template><script>
export default {name: 'Index',data () {return {}}
}
</script><style scoped>
</style>

修改 src/router/index.js 为:

import Vue from 'vue'
import Router from 'vue-router'
import Index from '../views/Index'Vue.use(Router)export default new Router({routes: [{path: '/',name: 'Index',component: Index}]
})

重新访问项目:

在这里插入图片描述

至此,前端项目的框架搭建完毕,接下来编写具体的页面。

3、相关依赖

# 使用element-ui,安装element-ui
npm i element-ui -S# 前后端交互axios
npm install axios# 数据存储vuex
npm install vuex --save# 安装字体
npm install font-awesome# 安装comment
npm install commentnpm install vue-router --save-dev
npm install sass-loader node-sass --save-dev

4、npm依赖下载失败解决

# npm清空下载的包
npm cache clean --force 或者
npm cache clear --force && npm install --no-shrinkwrap --update-binary

5、错误

【npm错误】- npm ERR code ERESOLVE 和 npm ERR ERESOLVE could not resolve 问题
# 解决
npm i --legacy-peer-deps

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/286806.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

20231218在Ubuntu18.04下以EXT4格式化HDD

20231218在Ubuntu18.04下以EXT4格式化HDD 2023/12/18 17:24 缘起&#xff1a; 编译一个Android10大概要200GB&#xff0c;编译10个Android10的SDK&#xff0c;3TB的HDD机械硬盘就估计会被填满了&#xff01; 如果使用rm -rf *这个命令将SDK一个一个逐个地删除&#xff0c;估计2…

VMware网络设置+Linux网卡设置+主机与虚拟机相互Ping通

目录 1. Linux网卡设置 1.1 ifcfg-ens33 1.2 修改配置信息 1.3 添加IP信息 1.4 重启网卡、关闭防火墙 2. VMware网络设置 3. 设置主机网络 4. 测试主机与虚拟机网络是否连通 4.1 主机ping虚拟机的Linux 4.2 虚拟机Linux来ping主机 1. Linux网卡设置 刚开始安装的Lin…

openGauss学习笔记-164 openGauss 数据库运维-备份与恢复-导入数据-使用COPY FROM STDIN导入数据-处理错误表

文章目录 openGauss学习笔记-164 openGauss 数据库运维-备份与恢复-导入数据-使用COPY FROM STDIN导入数据-处理错误表164.1 操作场景164.2 查询错误信息164.3 处理数据导入错误 openGauss学习笔记-164 openGauss 数据库运维-备份与恢复-导入数据-使用COPY FROM STDIN导入数据-…

基础算法(5):滑动窗口

1.何为滑动窗口&#xff1f; 滑动窗口其实也是一种算法&#xff0c;主要有两类&#xff1a;一类是固定窗口&#xff0c;一类是可变窗口。固定的窗口只需要一个变量记录&#xff0c;而可变窗口需要两个变量。 2.固定窗口 就像上面这个图一样。两个相邻的长度为4的红色窗口&…

【PHP入门】1.3-数据类型、转换、判断

-数据类型- 数据类型&#xff1a;data type&#xff0c;在 PHP中指的是存储的数据本身的类型&#xff0c;而不是变量的类型。 PHP是一种弱类型语言&#xff0c;变量本身没有数据类型。 1.3.1PHP的八种数据类型 在PHP中将数据分为三大类八小类&#xff1a; 简单&#xff0…

Arduino外部中断按钮输入控制继电器输出

目录 一、硬件 1、硬件介绍 2、Arduino外部 &#xff08;1&#xff09;中断引脚 &#xff08;2&#xff09;中断触发方式 &#xff08;3&#xff09;中断函数 二、外部中断0 三、外部中断0、外部中断1 一、硬件 1、硬件介绍 Adruino单片机、按钮、继电器。 按钮&…

UE5 Landscape地貌制作 - 学习笔记

P2. 创建地形 https://www.bilibili.com/video/BV1mD4y1D7D6?p2&spm_id_frompageDriver&vd_source707ec8983cc32e6e065d5496a7f79ee6 新建一个Basic场景选择Landscape Mode 生成预览网格&#xff08;绿色网格&#xff09;从文件导入&#xff1a;可以导入dem高度图地貌…

二叉树【数据结构】

目录 二叉树1. 二叉树定义二叉树的存储定义 2. 遍历二叉树(1) 前序遍历(2) 中序遍历(3) 后序遍历(4) 层序遍历 3. 二叉树的相关操作(1) 二叉树的初始化(2) 二叉树的结点的手动创建(3) 二叉树结点的个数(4) 二叉树叶子结点的个数(5) 二叉树的高度(6) 第k层结点个数(7) 通过前序遍…

Linux 特殊符号

目录 1. # 注释 2. &#xff1b;命令分隔符 3. .. 上级目录 4. . 当前目录 5. " " 换行&#xff0c;解析变量 6. 换行&#xff0c;不解析变量 7. \ 和 / 8. &#xff01;历史命令调用&#xff0c;取反 9. * 通配符 10. $ 调用变量 11. | 管道 12. || …

数据结构:树(Tree)

树型结构 树的概念 树是一种非线性结构&#xff0c;他是由n&#xff08;n>0&#xff09;个有限结点组成的一个具有层次关系的集合。 当n0时&#xff0c;该树为空树。 在任意一个非空树中都满足以下条件&#xff1a; 1、有一个特殊的结点&#xff0c;称为根结点&#xff0c…

统一系统脆弱性管理平台:七大功能和漏洞说“拜拜”

由国联易安的研究团队自主研发的新一代漏洞扫描管理系统——统一系统脆弱性管理平台&#xff0c;涵盖了网络空间资产探测、系统漏洞扫描、虚拟机漏洞扫描、Web漏洞扫描、网站安全监测、数据库安全扫描、安全基线核查、工控漏洞扫描、WiFi安全检测、App安全扫描、大数据平台漏洞…

Axure

目录 一. 交互 1.2 交互事件 二. 情形 2.1 应用场景 三. 案例 3.1 ERP登录 3.2 ERP页面跳转 一. 交互 交互事件是指在用户界面中发生某些操作或行为时&#xff0c;触发相应的响应或动作。在设计网页、应用程序或其他用户界面时&#xff0c;交互事件通常用于实现交互式功…