安装node.js 和 npm 的完整步骤1

vue 生命周期
1,beforeCreate    组件刚刚被创建
2,created         组件创建完成
3,beforeMount     挂载之前
4,mounted         挂载之后
5,beforeDestory   组件销毁前调用
6,destoryed       组件销毁后调用


<template>
	<h3>我爱你</h3>
</template>
<script>
	export default{
		data(){
			return{

			}
		},
		beforeCreate(){
			console.log("beforeCreate");
		},
		created(){
			console.log('created');
		},
		beforeMount(){
			console.log('beforeMount');
		},
		mounted(){
			console.log('mounted');
		},
		beforeDestory(){
			console.log('beforeDestory');
		},
		destoryed(){
			console.log('destoryed');
		}
	}
</script>
在Vue.js的生命周期中,可以分为6个阶段,也就是6个函数代表6个阶段,不管顺序如何变,还是会按照以下顺序去执行代码:
beforeCreate(创建前)——>created(创建后)——>beforeMount(载入前)——>mounted(载入后)——>beforeDestroy(销毁前)——>destroyed(销毁后)

卸载命令:
卸载vue-cli :  npm uninstall vue-cli -g
安装vue-cli :  npm install --global vue-cli
卸载cnpm : npm uninstall cnpm -g
安装cnpm : npm install


---------以下是安装vue项目完整步骤,一:-----------
安装npm步骤:(其实直接可以使用Git软件里面的命令控制面板安装查看,和安装 vue 各种执行文件)
1,Win+R 打开命令面板---输入cmd,回车---在命令面板输入以下命令来查看相关软件的版本号:
	a, node -v + 回车   直接百度安装node.js软件后再到命令控制面板查看版本号
		v10.16.2

	b, npm -v + 回车    安装完成node.js(npm是集成在node.js中的,如果nodejs安装成功,则npm也安装成功),
	如果有,则会出现版本号,否则就没有安装。
		6.9.0

	c, vue + 回车(这里是直接输入vue,没有-V)    安装成功后显示如下:(通过:npm install --global vue-cli 来安装的)
		$ vue
		Usage: vue <command> [options]

		Options:
		  -V, --version  output the version number <!-- 这里的V 一定是大写,才会出现版本号 -->
		  -h, --help     output usage information

		Commands:
		  init           generate a new project from a template
		  list           list available official templates
		  build          prototype a new project
		  create         (for v3 warning only)
		  help [cmd]     display help for [cmd]

2,先安装node.js 下载安装指定盘符即可。
3,win+R 进入命令控制面板 输入:path + 回车,安装成功会在下方显示node.js,可以仔细查找以下。
	path  为可执行文件显示或设置搜索路径(在命令控制面中输入:help,会出现一系列命令)
4,也可以直接输入 node -v 查看是否有安装成功,成功就会显示版本号。
5,安装:Git工具。
	进入某个盘符,直接输入   D: + 回车即可。
	但是如果要进入:D:\前端开发\HTML\组件化网页开发  步骤二 2-3 创建XMLHttpRequest对象\Ajax\register\img
	这样的路径,使用手写方式就很麻烦了,所以需要一个工具来帮忙,
	这个工具就是:官网:https://git-scm.com/  点击  DownLoads --- 选择相应系统的版本下载安装即可。
	安装完成,直接打开指定的文件夹,右击---选择---git bash  here 进入到此处的子程序
	马上就跳出一个在该路径下面的 node.js命令面板----就可以直接进行代码编写。
5,安装好node.js后,npm具体代码安装

---------步骤二:(Win + R)在控制面板中输入以下命令行-----------
#全局安装 vue-cli 分为两种情况:
	一,使用npm,访问国外网站。
	输入:npm install --global vue-cli
	(这里的npm是访问国外的网站,下载速度很慢。所以,可以使用淘宝镜像的cnpm)
	回车等待下载完成,显示如下:

		韦德君@LAPTOP-AKTJNVLT MINGW64 /d/泉州时代/学习/vue.js
		$ npm install --global vue-cli
		npm WARN deprecated [email protected]: This package has been deprecated in favour of @vue/cli
		npm WARN deprecated [email protected]: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
		C:\Users\30467\AppData\Roaming\npm\vue -> C:\Users\30467\AppData\Roaming\npm\node_modules\vue-cli\bin\vue
		C:\Users\30467\AppData\Roaming\npm\vue-list -> C:\Users\30467\AppData\Roaming\npm\node_modules\vue-cli\bin\vue-list
		C:\Users\30467\AppData\Roaming\npm\vue-init -> C:\Users\30467\AppData\Roaming\npm\node_modules\vue-cli\bin\vue-init
		+ [email protected]
		added 241 packages from 206 contributors in 150.212s
		韦德君@LAPTOP-AKTJNVLT MINGW64 /d/泉州时代/学习/vue.js


	二,使用国内网站,淘宝的镜像。
	不使用上面国外的npm,改为使用使用淘宝npm镜像的步骤:
	1,输入:npm install -g cnpm --registry=https://registry.npm.taobao.org/ + 按回车
		显示如下;

		韦德君@LAPTOP-AKTJNVLT MINGW64 /d/泉州时代/学习/vue.js
		$ npm install -g cnpm --registry=https://registry.npm.taobao.org/
		C:\Users\30467\AppData\Roaming\npm\cnpm -> C:\Users\30467\AppData\Roaming\npm\node_modules\cnpm\bin\cnpm
		+ [email protected]
		added 680 packages from 928 contributors in 121.079s

		<!-- 如果是重复安装,那么就是进行更新操作,最后一局可能会变成:
		updated 2 packages in 74.538s -->



	2,输入: cnpm install --global vue-cli  +  回车。
		显示如下:才算成功安装
			韦德君@LAPTOP-AKTJNVLT MINGW64 /d/泉州时代/学习/vue.js
			cnpm install --global vue-cli
			Downloading vue-cli to C:\Users\30467\AppData\Roaming\npm\node_modules\vue-cli_tmp
			Copying C:\Users\30467\AppData\Roaming\npm\node_modules\vue-cli_tmp\[email protected]@vue-cli to C:\Users\30467\AppData\Roaming\npm\node_modules\vue-cli
			Installing vue-cli's dependencies to C:\Users\30467\AppData\Roaming\npm\node_modules\vue-cli/node_modules
			[1/20] commander@^2.9.0 installed at node_modules\[email protected]@commander
			[2/20] ora@^1.3.0 installed at node_modules\[email protected]@ora
			[3/20] minimatch@^3.0.0 installed at node_modules\[email protected]@minimatch
			[4/20] multimatch@^2.1.0 installed at node_modules\[email protected]@multimatch
			[5/20] rimraf@^2.5.0 existed at node_modules\[email protected]@rimraf
			[6/20] consolidate@^0.14.0 installed at node_modules\[email protected]@consolidate
			[7/20] chalk@^2.1.0 installed at node_modules\[email protected]@chalk
			[8/20] semver@^5.1.0 installed at node_modules\[email protected]@semver
			[9/20] tildify@^1.2.0 installed at node_modules\[email protected]@tildify
			[10/20] [email protected] installed at node_modules\[email protected]@uid
			[11/20] user-home@^2.0.0 installed at node_modules\[email protected]@user-home
			[12/20] read-metadata@^1.0.0 installed at node_modules\[email protected]@read-metadata
			[13/20] [email protected] existed at node_modules\[email protected]@coffee-script
			[14/20] validate-npm-package-name@^3.0.0 installed at node_modules\[email protected]@validate-npm-package-name
			[15/20] metalsmith@^2.1.0 installed at node_modules\[email protected]@metalsmith
			[16/20] handlebars@^4.0.5 installed at node_modules\[email protected]@handlebars
			[17/20] download-git-repo@^1.0.1 installed at node_modules\[email protected]@download-git-repo
			[18/20] request@^2.67.0 installed at node_modules\[email protected]@request
			[19/20] async@^2.4.0 installed at node_modules\[email protected]@async
			[20/20] inquirer@^6.0.0 installed at node_modules\[email protected]@inquirer
			deprecate [email protected][email protected] › coffee-script@^1.12.4 CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
			Recently updated (since 2019-11-05): 2 packages (detail see file C:\Users\30467\AppData\Roaming\npm\node_modules\vue-cli\node_modules\.recently_updates.txt)
			  2019-11-07
			    → [email protected][email protected] › glob@^7.1.3(7.1.6) (06:07:44)
			  2019-11-06
			    → [email protected] › uglify-js@^3.1.4(3.6.8) (16:49:20)
			All packages installed (239 packages installed from npm registry, used 28s(network 27s), speed 191.86kB/s, json 223(438.7kB), tarball 4.55MB)
			[[email protected]] link C:\Users\30467\AppData\Roaming\npm\vue@ -> C:\Users\30467\AppData\Roaming\npm\node_modules\vue-cli\bin\vue
			[[email protected]] link C:\Users\30467\AppData\Roaming\npm\vue-init@ -> C:\Users\30467\AppData\Roaming\npm\node_modules\vue-cli\bin\vue-init
			[[email protected]] link C:\Users\30467\AppData\Roaming\npm\vue-list@ -> C:\Users\30467\AppData\Roaming\npm\node_modules\vue-cli\bin\vue-list
			<!-- 安装成功,上面是最后一句代码 -->

----------步骤三:使用git打开指定目录,创建webpack模板的新项目----------
如果这里不适用Git工具,那么就必须在命令控制面板中找到指定目录下再执行以下命令
如果node.js 和 npm/cnpm 已经安装完毕,
需要创建新的项目,则直接执行后面的几个步骤即可。有时候会运行失败,不知道是什么情况。
此外,不能在已经创建好的项目中创建另外一个项目,否则直接报错。
-------------------------------------------------
<!-- 下面的:这里必须注意,	? Install vue-router? (Y/n) Y  一定要输入Y,即YES -->
#创建一个基于webpack模板的新项目
	输入:vue init webpack my-project

	显示如下:
	韦德君@LAPTOP-AKTJNVLT MINGW64 /d/泉州时代/学习/vue.js
	$ vue init webpack my-project

	? Project name (my-project)  <!-- 是否把项目命名为(my-project) 直接回车即可(默认肯定) -->
	? Project name my-project
	? Project description (A Vue.js project)  <!-- 是否进行项目描述  直接回车即可(默认肯定) -->
	? Project description A Vue.js project
	? Author       <!-- 是否填写作者       直接回车即可(默认肯定) -->
	? Author
	? Vue build standalone    <!-- 是否独立创建Vue   直接回车即可(默认肯定) -->
	? Install vue-router? (Y/n) Y  <!-- 这里必须注意,一定要输入Y,即YES -->
	? Install vue-router? Yes
	? Use ESLint to lint your code? (Y/n) n
	? Use ESLint to lint your code? No
	? Set up unit tests (Y/n) n
	? Set up unit tests No
	? Setup e2e tests with Nightwatch? (Y/n) n
	? Setup e2e tests with Nightwatch? No
	? Should we run `npm install` for you after the project has been created? (recom
	? Should we run `npm install` for you after the project has been created? (recom
	mended) npm

	   vue-cli · Generated "my-project".


	# Installing project dependencies ...
	# ========================

	npm WARN deprecated [email protected]: Deprecated. Please use https://github.com/webpack-contrib/mini-css-extract-plugin
	npm WARN deprecated [email protected]: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
	npm WARN deprecated [email protected]: Switch to the `bfj` package for fixes and new features!
	<!-- 安装成功上面是最后一句代码 -->
	<!-- 安装成功以下是警告,可能有可能没有: -->
	npm WARN deprecated [email protected]: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
	npm WARN deprecated [email protected]: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.



	这样项目模板就算创建完毕了 ,ctrl + C 退出命令控制面板。
	按完 Ctrl + C 就会跳转到如下:
		韦德君@LAPTOP-AKTJNVLT MINGW64 /d/泉州时代/学习/vue.js
		$

	注意点: vue init webpack my-projectSecond  项目名称不能有大写字母,否则直接报错,如下:
	? Project name (my-projectSecond) my-projectSecond
	>> Sorry, name can no longer contain capital letters.


	----------步骤四:输入下面的几句代码----------
	#安装依赖包
		1,输入:cd my-project + 回车   没有其他显示,只是换行继续输入下面一句代码。
		2,输入:cnpm install + 回车 (淘宝镜像使用) / npm install (下载国外的npm才使用)
			显示如下:
				韦德君@LAPTOP-AKTJNVLT MINGW64 /d/泉州时代/学习/vue.js/my-project
				$ cnpm install
				platform unsupported [email protected][email protected][email protected][email protected] › fsevents@^1.2.7 Package require os(darwin) not compatible with your platform(win32)
				[fsevents@^1.2.7] optional install error: Package require os(darwin) not compatible with your platform(win32)
				√ Installed 37 packages
				√ Linked 744 latest versions
				[1/2] scripts.postinstall [email protected][email protected] › uglifyjs-webpack-plugin@^0.4.6 run "node lib/post_install.js", root: "D:\\泉州时代\\学习\\vue.js\\my-project\\node_modules\\[email protected]@uglifyjs-webpack-plugin"
				[1/2] scripts.postinstall [email protected][email protected] › uglifyjs-webpack-plugin@^0.4.6 finished in 671ms
				[2/2] scripts.postinstall [email protected][email protected] › core-js@^2.5.0 run "node postinstall || echo \"ignore\"", root: "D:\\泉州时代\\学习\\vue.js\\my-project\\node_modules\\[email protected]@core-js"
				Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

				The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
				> https://opencollective.com/core-js
				> https://www.patreon.com/zloirock

				Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)

				[2/2] scripts.postinstall [email protected][email protected] › core-js@^2.5.0 finished in 751ms
				√ Run 2 scripts
				deprecate [email protected] › browserslist@^2.11.3 Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
				deprecate extract-text-webpack-plugin@^3.0.0 Deprecated. Please use https://github.com/webpack-contrib/mini-css-extract-plugin
				deprecate [email protected][email protected][email protected] › browserslist@^1.7.6 Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
				deprecate [email protected][email protected][email protected][email protected] › fsevents@^1.2.7 One of your dependencies needs to upgrade to fsevents v2: 1) Proper nodejs v10+ support 2) No more fetching binaries from AWS, smaller package size
				deprecate [email protected] › bfj-node4@^5.2.0 Switch to the `bfj` package for fixes and new features!
				Recently updated (since 2019-11-05): 12 packages (detail see file 
				<!-- 安装成功表现一:一定会标注最近一次更新的时间是:(since 2019-11-05) -->
				D:\泉州时代\学习\vue.js\my-project\node_modules\.recently_updates.txt)
				√ All packages installed (920 packages installed from npm registry, used 1m(network 1m), speed 253.07kB/s, json 781(1.73MB), tarball 18.3MB)
				<!-- 安装成功表现二:上面是最后一句代码,一定是: √ All... -->

				韦德君@LAPTOP-AKTJNVLT MINGW64 /d/泉州时代/学习/vue.js/my-project

		3,输入:npm run dev  + 回车 (让项目跑起来,淘宝镜像和国外npm都可以使用,因为没有涉及下载)
		显示如下:
			韦德君@LAPTOP-AKTJNVLT MINGW64 /d/泉州时代/学习/vue.js/my-project
			$ npm run dev  (不管是淘宝镜像的 cnpm 还是直接使用 npm,启动都是用:npm run dev)

			> [email protected] dev D:\泉州时代\学习\vue.js\my-project
			> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js


			D:\Ȫ▒▒ʱ▒▒\ѧϰ\vue.js\my-project>"node"  "D:\Ȫ▒▒ʱ▒▒\ѧϰ\vue.js\my-project\node_modules\.bin\\..\[email protected]@webpack-dev-server\bin\webpack-dev-server.js" --inline --progress --config build/webpack.dev.conf.js
			 10% building modules 0/1 modules 1 active ... webpack/hot/dev-server ./src/main 10% building modules 1/2 modules 1 active ...泉州时代\学习\vue.js\my-project\sr 10% building modules 2/3 modules 1 active ...client\index.js?http://localhost:8 10% building modules 3/4 modules 1 active ...\webpack\hot nonrecursive /^\.\/lo 10% building modules 3/5 modules 2 active ...5@webpack-dev-server\client\socket 10% building modules 3/6 modules 3 active ...@webpack-dev-server\client\overlay 10% building modules 3/7 modules 4 active [email protected]@webpack\hot\dev-server 10% building modules 4/7 modules 3 active [email protected]@webpack\hot\dev-server 10% building modules 4/8 modules 4 active ...vue.js\my-project\src\router\index 10% building modules 5/8 modules 3 active ...vue.js\my-project\src\router\index 10% building modules 6/8 modules 2 active ...vue.js\my-project\src\router\index 10% building modules 7/8 modules 1 active ...vue.js\my-project\src\router\index 10% building modules 7/9 modules 2 active [email protected]@webpack\hot\emitter 10% building modules 7/10 modules 3 active ...dules\[email protected]@vue\dist\vue.es 10% building modules 7/11 modules 4 active ...t\node_modules\[email protected]@url\ur 10% building modules 8/11 modules 3 active ...t\node_modules\[email protected]@url\ur 11% building modules 9/11 modules 2 active ...t\node_modules\[email protected]@url\ur 11% building modules 9/12 modules 3 active ...es\[email protected]@webpack\hot\lo 11% building modules 9/13 modules 4 active ....12.0@webpack\hot\log-apply-resul 11% building modules 10/13 modules 3 active ....12.0@webpack\hot\log-apply-resu 11% building modules 11/13 modules 2 active ...t\node_modules\[email protected]@url\u 11% building modules 11/14 modules 3 active ...泉州时代\学习\vue.js\my-project\ 11% building modules 11/15 modules 4 active ...project\src\components\HelloWorl 11% building modules 11/16 modules 5 active [email protected]@loglevel\lib\loglev 11% building modules 12/16 modules 4 active [email protected]@loglevel\lib\loglev 11% building modules 13/16 modules 3 active [email protected]@loglevel\lib\loglev 11% building modules 13/17 modules 4 active ...odules\[email protected]@events\even 11% building modules 14/17 modules 3 active ...odules\[email protected]@events\even 11% building modules 14/18 modules 4 active [email protected]@strip-ansi\ind 11% building modules 14/19 modules 5 active [email protected]@sockjs-client\dist\sock 11% building modules 15/19 modules 4 active [email protected]@sockjs-client\dist\sock 11% building modules 15/20 modules 5 active ...\node_modules\[email protected]@url\ut 11% building modules 15/21 modules 6 active ...s\[email protected]@ansi-html\ind 11% building modules 15/22 modules 7 active [email protected]@querystring-es3\ind 11% building modules 15/23 modules 8 active ...\[email protected]@punycode\punyco 11% building modules 15/24 modules 9 active ...泉州时代\学习\vue.js\my-project\ 11% building modules 15/25 modules 10 active ...project\src\components\HelloWor 11% building modules 16/25 modules 9 active ...project\src\components\HelloWorl 12% building modules 17/25 modules 8 active ...\[email protected]@punycode\punyco 12% building modules 17/26 modules 9 active ...ue-loader\lib\component-normaliz 12% building modules 18/26 modules 8 active ...ue-loader\lib\component-normaliz 12% building modules 18/27 modules 9 active ...泉州时代\学习\vue.js\my-project\ 12% building modules 18/28 modules 10 active ...project\src\components\HelloWorld.vue{ parser: "babylon" } is deprecated; we now treat it as { parser: "babel" }.
			 12% building modules 19/28 modules 9 active ...project\src\components\HelloWorl 12% building modules 20/28 modules 8 active ...ue-loader\lib\component-normaliz 12% building modules 21/28 modules 7 active ...ue-loader\lib\component-normaliz 12% building modules 22/28 modules 6 active ...ue-loader\lib\component-normaliz 12% building modules 22/29 modules 7 active [email protected]@html-entities\ind 12% building modules 23/29 modules 6 active [email protected]@html-entities\ind 12% building modules 24/29 modules 5 active [email protected]@html-entities\ind 13% building modules 25/29 modules 4 active [email protected]@html-entities\ind 13% building modules 25/30 modules 5 active ...1.3@vue-router\dist\vue-router.e 13% building modules 26/30 modules 4 active ...1.3@vue-router\dist\vue-router.e 13% building modules 27/30 modules 3 active ...1.3@vue-router\dist\vue-router.e 13% building modules 27/31 modules 4 active [email protected]@querystring-es3\deco 13% building modules 27/32 modules 5 active [email protected]@querystring-es3\enco 13% building modules 27/33 modules 6 active ...2.1@html-entities\lib\xml-entiti 13% building modules 27/34 modules 7 active ...1@html-entities\lib\html4-entiti 13% building modules 27/35 modules 8 active ...1@html-entities\lib\html5-entiti 13% building modules 27/36 modules 9 active [email protected]@webpack\buildin\modu 13% building modules 27/37 modules 10 active [email protected]@webpack\buildin\glo 13% building modules 28/37 modules 9 active [email protected]@webpack\buildin\glob 13% building modules 29/37 modules 8 active [email protected]@webpack\buildin\glob 13% building modules 30/37 modules 7 active [email protected]@webpack\buildin\glob 13% building modules 31/37 modules 6 active [email protected]@webpack\buildin\glob 13% building modules 32/37 modules 5 active ...1@html-entities\lib\html5-entiti 13% building modules 32/38 modules 6 active ....3.4@vue-hot-reload-api\dist\ind 13% building modules 32/39 modules 7 active ...泉州时代\学习\vue.js\my-project\ 13% building modules 33/39 modules 6 active ....3.4@vue-hot-reload-api\dist\ind 13% building modules 33/40 modules 7 active ...project\src\components\HelloWorl 14% building modules 34/40 modules 6 active ....3.4@vue-hot-reload-api\dist\ind 14% building modules 35/40 modules 5 active ....3.4@vue-hot-reload-api\dist\ind 14% building modules 35/41 modules 6 active ...泉州时代\学习\vue.js\my-project\ 14% building modules 35/42 modules 7 active ...project\src\components\HelloWorl 14% building modules 36/42 modules 6 active ...project\src\components\HelloWorl 14% building modules 37/42 modules 5 active ...project\src\components\HelloWorl 14% building modules 37/43 modules 6 active ...e-style-loader\lib\addStylesClie 14% building modules 38/43 modules 5 active ...e-style-loader\lib\addStylesClie 14% building modules 39/43 modules 4 active ...e-style-loader\lib\addStylesClie 14% building modules 39/44 modules 5 active ...vue.js\my-project\src\assets\log 14% building modules 40/44 modules 4 active ...vue.js\my-project\src\assets\log 14% building modules 40/45 modules 5 active [email protected]@ansi-regex\ind 14% building modules 41/45 modules 4 active [email protected]@ansi-regex\ind 15% building modules 42/45 modules 3 active [email protected]@ansi-regex\ind 15% building modules 42/46 modules 4 active ...@vue-style-loader\lib\listToStyl 15% building modules 43/46 modules 3 active ...@vue-style-loader\lib\listToStyl 15% building modules 44/46 modules 2 active ...@vue-style-loader\lib\listToStyl 15% building modules 45/46 modules 1 active ...@vue-style-loader\lib\listToStyl 15% building modules 46/47 modules 1 active [email protected]@css-loader\lib\css-ba 95% emitting DONE  Compiled successfully in 14781ms4:18:45 PM

			 I  Your application is running here: http://localhost:8080
			韦德君@LAPTOP-AKTJNVLT MINGW64 /d/泉州时代/学习/vue.js/my-project

	最后可以在网页地址栏输入:http://localhost:8080 进行访问。
	注意,该命令控制面板是不能关闭的,否则就无法正常打开页面。
	如果不小心关闭了,则使用Git在创建项目的文件夹中右击:Git Bash Here 进入该子程序。
	然后再执行:npm run dev  +  回车    等待运行完成。

=======================================
打开页面一定要有两个特点:
1,一定有路由 router(路由是需要配置的)  英 /'ruːtə(r)/路由器,路由
2,一定有一个页面(该页面是 .vue 格式的)

  

猜你喜欢

转载自www.cnblogs.com/Knowledge-is-infinite/p/12191446.html
今日推荐