vue.js 安装

环境准备:mac

NPM 方法(推荐)

由于 npm 安装速度慢,本教程使用了淘宝的镜像及其命令 cnpm,安装使用介绍参照:使用淘宝 NPM 镜像

npm 版本需要大于 3.0,如果低于此版本需要升级它:

使用淘宝 NPM 镜像

$ npm install -g cnpm --registry=https://registry.npm.taobao.org

踩坑
$ npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules

解决方法:
$ sudo npm install -g cnpm --registry=https://registry.npm.taobao.org

安装路径:/usr/local/lib/node_modules/cnpm/bin/cnpm

这样就可以使用 cnpm 命令来安装模块了:

$ cnpm install [name]
 
#升级 npm(可以忽略)
$sudo cnpm install npm-g

在用 Vue.js 构建大型应用时推荐使用 NPM 安装:

#最新稳定版
$ cnpm install vue

命令行工具

Vue.js 提供一个官方命令行工具,可用于快速搭建大型单页应用。

# 全局安装 vue-cli
$ cnpm install --global vue-cli
# 创建一个基于 webpack 模板的新项目
$ vue init webpack my-project
# 这里需要进行一些配置,默认回车即可
This will install Vue 2.x version of the template.

For Vue 1.x use: vue init webpack#1.0 my-project

? Project name my-project
? Project description A Vue.js project
? Author runoob <>
? Vue build standalone
? Use ESLint to lint your code? Yes
? Pick an ESLint preset Standard
? Setup unit tests with Karma + Mocha? Yes
? Setup e2e tests with Nightwatch? Yes

   vue-cli · Generated "my-project".

   To get started:
   
     cd my-project
     npm install
     npm run dev
   
   Documentation can be found at https://vuejs-templates.github.io/webpack

进入项目,安装并运行: 

$ cd my-project
$ cnpm install
$ cnpm run dev
 DONE  Compiled successfully in 4388ms

> Listening at http://localhost:8080

成功执行以上命令后访问 http://localhost:8080/,输出结果如下所示:

vue.js 安装

注意:Vue.js 不支持 IE8 及其以下 IE 版本。

安装npm全局包提示没有写入权限解决办法

修改npm包所安装目录的权限:sudo chown -R $USER /usr/local   然后输入密码就可以了

踩坑: chown: /usr/local: Operation not permitted

解决方法:
卸载Homebrew:
 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

然后重新安装它:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 输入密码:

 

参考链接:https://stackoverflow.com/questions/46459152/cant-chown-usr-local-for-homebrew-in-mac-os-x-10-13-high-sierra

相关推荐