1,安装node.js(同时也安装了npm)
- windows系统:点击下载nodejs
- 下载后双击安装即可(npm也安装好了)
- 安装完成后用可以用
node --version
查看nodejs的版本,注意不要安装太旧的版本
2,npm相关方法
# 查看版本
$ npm -v
2.3.0
#升级 npm
cnpm install npm -g
# 升级或安装 cnpm
npm install cnpm -g
3,安装vue
# 最新稳定版
$ cnpm install vue
相关命令
# 全局安装 vue-cli
$ cnpm install --global vue-cli
# 创建一个基于 webpack 模板的新项目,项目名为my-project
$ vue init webpack my-project
# 这里需要进行一些配置,默认回车即可
? Project name my-project
? Project description A Vue.js project
? Author xumlin <857194181@qq.com>
? Vue build standalone
? Install vue-router? Yes
? Use ESLint to lint your code? Yes
? Pick an ESLint preset Standard
? Set up unit tests Yes
? Pick a test runner jest
? Setup e2e tests with Nightwatch? Yes
? Should we run `npm install` for you after the project has been created? (recommended
) npm
vue-cli · Generated "my-project".
# Installing project dependencies ...
# ========================
npm WARN deprecated browserslist@2.11.3: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated bfj-node4@5.3.1: Switch to the `bfj` package for fixes and new features!
npm WARN deprecated browserslist@1.7.7: Browserslist 2 could fail on reading Browserslist >3.0 config used in other tools.
npm WARN deprecated circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
npm WARN deprecated socks@1.1.10: If using 2.x branch, please upgrade to at least 2.1.6 to avoid a serious bug with socket data flow and an import issue introduced in 2.1.0
> chromedriver@2.43.1 install C:\Users\fengjiabin\my-project\node_modules\chromedriver
> node install.js
Downloading https://chromedriver.storage.googleapis.com/2.43/chromedriver_win32.zip
Saving to C:\Users\FENGJI~1\AppData\Local\Temp\chromedriver\chromedriver_win32.zip
Received 781K...
Received 1563K...
Received 2345K...
Received 3128K...
Received 3529K total.
Extracting zip contents
Copying to target path C:\Users\fengjiabin\my-project\node_modules\chromedriver\lib\chromedriver
Done. ChromeDriver binary available at C:\Users\fengjiabin\my-project\node_modules\chromedriver\lib\chromedriver\chromedriver.exe
> uglifyjs-webpack-plugin@0.4.6 postinstall C:\Users\fengjiabin\my-project\node_modules\webpack\node_modules\uglifyjs-webpack-plugin
> node lib/post_install.js
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN ajv-keywords@2.1.1 requires a peer of ajv@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
added 1594 packages from 1095 contributors and audited 30831 packages in 332.46s
found 8 vulnerabilities (1 low, 1 moderate, 5 high, 1 critical)
run `npm audit fix` to fix them, or `npm audit` for details
Running eslint --fix to comply with chosen preset rules...
# ========================
> my-project@1.0.0 lint C:\Users\fengjiabin\my-project
> eslint --ext .js,.vue src test/unit test/e2e/specs "--fix"
# Project initialization finished!
# ========================
To get started:
cd my-project
npm run dev
Documentation can be found at https://vuejs-templates.github.io/webpack
4,进入项目,安装并运行项目
进入:$ cd my-project
安装:$ cnpm install
运行:$ cnpm run dev
最后出现:I Your application is running here: http://localhost:8081
C:\Users\fengjiabin>cd my-project
C:\Users\fengjiabin\my-project>cnpm install
√ Installed 58 packages
√ Linked 0 latest versions
√ Run 0 scripts
√ All packages installed (used 31ms(network 28ms), speed 0B/s, json 0(0B), tarball 0B)
C:\Users\fengjiabin\my-project>cnpm run dev
> my-project@1.0.0 dev C:\Users\fengjiabin\my-project
> webpack-dev-server --inline --progress --config build/webpack.dev.conf.js
95% emitting
DONE Compiled successfully in 3700ms 14:29:43
I Your application is running here: http://localhost:8081
最后在浏览器访问:http://localhost:8081
,出现如下界面,表示vuejs就安装完成了
5,总结
在使用cnpm install vue
命令的时候可能会出现以下错误:
原因:
出现这个错误的原因是安装的node.js版本太低了,升级版本。
注意:Vue.js 不支持 IE8 及其以下 IE 版本。