vue 起步
# 全局安装 vue-cli $ npm install —global vue-cli # 创建一个基于 webpack 模板的新项目 $ vue init webpack my-project # 安装依赖,走你 $ cd my-project $ npm install $ npm run dev |
Vue.js是前端一个比较火的MVVM框架,要使用它,我们必须提前配置,其中有一种安装方式是使用npm,比较适合比较大型的应用。今天就来看看这种方式如何操作,由于npm是国外的,使用起来比较慢,我们这里使用淘宝的cnpm镜像来安装vue.
步骤
首先我们需要下载npm,因为我已经提前安装了node.js,安装包里面集成了npm,然后我们就可以利用npm命令从获取淘宝镜像的cnpm了。
1.打开命令行窗口,输入
npm install -g cnpm --registry=https://registry.npm.taobao.org
- 1
获取到cnpm以后,我们需要升级一下,输入下面的命令
cnpm install cnpm -g
- 1
因为安装Vue需要npm的版本大于3.0.0,所以我们要升级一下,
然后我们输入下面的命令,安装vue
cnpm install vue
- 1
接下来安装vue-cli
cnpm install --global vue-cli
- 1
此时环境就搭建好了。
2.接下来我们需要指定一个目录存放我们的项目,可以选择任意路径,确定好路径后输入下面的命令
vue init webpack "项目名称"
- 1
3.成功以后,我们进入项目所在目录
cd "项目所在文件夹"
- 1
然后依次输入下面的命令
cnpm install cnpm run dev
- 1
- 2
成功后我们进入浏览器,输入localhost:8080会展示下面的页面
replenish:
vue init webpack-simple project 报错处理(connect ETIMEDOUT 192.30.253.112)
1 | Failed to download repo vuejs-templates/webpack-simple: connect ETIMEDOUT 192.30.253.113:443 |
Failed to download repo vuejs-templates/webpack-simple: connect ETIMEDOUT 192.30.253.112:443,一直报这个错
解决步骤:
1.打开终端(cmd),输入命令:ping 192.30.253.112 发现连接超时;输入命令:ping github.com 显示超时。
2.打开 hosts文件,地址:C:\Windows\System32\drivers\etc 看是否是默认配置。默认配置如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a ‘#’ symbol. # # For example: # # 102.54.94.97 rhino.acme.com # source server # 38.25.63.10 x.acme.com # x client host # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost |
如果不是,还原成默认配置。
无法连接github
1.打开终端(cmd),输入命令:ping 192.30.253.112 发现连接超时;输入命令:ping github.com 显示超时。
2.打开 hosts文件,地址:C:WindowsSystem32driversetc 看是否是默认配置。
3.在本地hosts文件中加入:
- 192.30.253.112 github.com
- 151.101.88.249 github.global.ssl.fastly.net>
### 如果本地已经做了代理
1、关闭npm的https
npm config set strict-ssl false
2、设置npm的获取地址
npm config set registry "http://registry.npmjs.org/"
离线构建项目
reference:
https://segmentfault.com/q/1010000005998968
1.下载模板
在https://github.com/vuejs-templates/
下载webpack-simple 或 webpack。比如: 到 https://github.com/vuejs-templates/webpack-simple点Clone or Download 里的 Download ZIP
下个lantern或者挂vpnFQ,此处不赘述
2.解压zip,放置文件夹
把解压出的文件夹放在
C:\Users\{your username}\.vue-templates
比如我的用户名是jj, 那就是
C:\Users\jj\.vue-templates3.离线执行vue init
到你的project的文件夹,执行
vue init webpack project --offline
或vue init webpack-simple project --offline
与原本指令的区别
在于加了—offline, 于是你的vue init是用
C:\Users\{your username}\.vue-templates
内的template来生成项目的
转载于//www.cnblogs.com/tongbiao/p/7742537.html
还没有评论,来说两句吧...