vue.js安装心得

时间:2022-06-13
本文章向大家介绍vue.js安装心得,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

npm是nodejs的包管理器,所以之前只想找npm,而不想下载nodejs,最后闹了笑话。

最后是根据这篇博客安装成功的: npm安装教程

最好下载安装包,之前在mac电脑上用命令安装失败了

brew install node

npm安装包下载地址:https://nodejs.org/en/

走了不少弯路,首先报了权限不足的问题,这个问题可以通过修改配置解决:

npm config set prefix "D:nodejsnode_global"
npm config set cache "D:nodejsnode_cache"

其次是设置镜像,可以加快下载速度:

npm config set registry=http://registry.npm.taobao.org

如果想去掉淘宝镜像:

npm config set registry https://registry.npmjs.org

然后就是安装vue相关的:

npm install vue-router -g
npm install vue-cli -g
//初始化项目
vue init webpack <项目名>

最新版本在mac上提示错误:

Unknown command init.

可以先配置vue路径:在.bash_profile下加入之前配置的node_global目录路径,然后执行:

vue-init webpack <项目名>

然后居然成功了。

然后就是一系列Yes/No,可以根据自己的要求输入’y’或者’n’:

? Project name <项目名>
? Project description A Vue.js project
? Author
? 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

得到以下提示:

# Project initialization finished!
# ========================

To get started:

  cd vue01
  npm run dev

Documentation can be found at https://vuejs-templates.github.io/webpack

然后跟着提示走就行了。

关于打包,使用以下命令:

npm run build

但是路径貌似有问题,需要配置一下根路径,或者去掉链接最开始的’/’ 可以修改configuration/index.js

...
build:{
...
    assetsPublicPath: './',
...
}
...


npm install 卡在下载某个包的过程中。可以这样处理:

  1. 打开log
npm ERR! A complete log of this run can be found in:
npm ERR!     F:workspacenodejsnode_cache_logs2018-04-13T14_03_04_738Z-debug.log //日志路径
  1. 用浏览器输入地址(或其他方式)下载所需要的包,如https://cdn.npm.taobao.org/fsevents/-/fsevents-1.1.3.tgz
  2. 用以下命令把下载到的包添加到npm cache目录中:
npm cache add xxx.tgz
  1. 重新执行npm install,它便会使用本地缓存的xxx.tgz,而跳过下载过程。
...
npm http fetch GET 304 http://registry.npm.taobao.org/fsevents 218ms (from cache)
...