NPM 方法
由于 npm 安装速度慢,本教程使用了淘宝的镜像及其命令 cnpm,
安装使用介绍参照,使用淘宝 NPM 镜像:npm install -g cnpm --registry=https://registry.npm.taobao.org
npm 版本需要大于 3.0,如果低于此版本需要升级它:
# 查看版本 $ npm -v 2.3.0 #升级 npm cnpm install npm -g # 升级或安装 cnpm npm install cnpm -g
在用 Vue.js 构建大型应用时推荐使用 cnpm 安装,cnpm 能很好地和 Webpack 或 Browserify 模块打包器配合使用:
# 最新稳定版 $ cnpm install vue@next
命令行工具
Vue.js 提供一个官方命令行工具,可用于快速搭建大型单页应用。
# 全局安装 vue-cli $ cnpm install -g @vue/cli
# 安装完后查看版本 $ vue --version @vue/cli 4.5.11
注意:vue-cli 3.x 和 vue-cli 2.x 使用了相同的 vue 命令,如果你之前已经安装了 vue-cli 2.x,它会被替换为 Vue-cli 3.x。
安装 @vue/cli-int:
$ cnpm i -g @vue/cli-init
创建项目
$ vue init webpack runoob-vue3-test # 这里需要进行一些配置,默认回车即可 ? Project name runoob-vue3-test ? Project description A Vue.js project ? Author runoob <test@runoob.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 "runoob-vue3-test". # Installing project dependencies ... # ======================== ...
进入项目,安装并运行:
$ cd runoob-vue3-test $ cnpm run dev DONE Compiled successfully in 2558ms I Your application is running here: http://localhost:8080
成功执行以上命令后访问 http://localhost:8080/,输出结果如下所示:
注意:Vue.js 不支持 IE8 及其以下 IE 版本。