涉及内容

html  css   javascript   node.js   npm    webpack

2.9.6是常用版本

vue-cli4是基于webpack的

webpack是基于node.js的

npm:node package manager,是nodejs的包管理器,通常使用淘宝镜像;这是npmjs.org的一个镜像,由于在国内,网速相对国外快。该镜像每十分钟与官方同步一次。

下载nodejs并安装或者yum/apt-get安装

https://cdn.npm.taobao.org/dist/node/v14.4.0/node-v14.4.0-linux-x64.tar.xz

tar -xvf node-v14.4.0-linux-x64.tar.xz

sudo apt-get install nodejs

sudo apt-get install npm

sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
$ cnpm -v
cnpm@6.1.1 (/usr/local/lib/node_modules/cnpm/lib/parse_argv.js)
npm@6.14.5 (/usr/local/lib/node_modules/cnpm/node_modules/npm/lib/npm.js)
node@10.19.0 (/usr/bin/node)
npminstall@3.27.0 (/usr/local/lib/node_modules/cnpm/node_modules/npminstall/lib/index.js)
prefix=/usr/local
linux x64 5.4.0-39-generic
registry=https://r.npm.taobao.org

yarn是facebook公司用于替代npm的一个包管理器

sudo npm i yarn -g -verbose
sudo yarn config set registry https://registry.npm.taobao.org
$ yarn -v
1.22.4

安装vue-cli 3或4版本说明

本地安装会安装到当前目录

cnpm install @vue/cli

$ ls
node_modules

vue-cli 2版本的安装方式

npm install -g vue-cli

安装指定版本

2版本:cnpm install -g vue-cli@版本号

3及以上版本:cnpm install -g @vue/cli@版本号

正式安装

sudo cnpm install -g @vue/cli

安装vue-cli模块到/usr/local/lib/node_modules,并创建下面的链接(下面的链接是自动创建的,无须再重复创建),于是可以全局使用vue

[@vue/cli@4.4.6] link /usr/local/bin/vue@ -> /usr/local/lib/node_modules/@vue/cli/bin/vue.js

$ vue -V
@vue/cli 4.4.6

创建项目

Babel转码器,把EC6/7代码转换为浏览器可以识别的编码

至少需要安装Babel和Router

vue create vue2

Vue CLI v4.4.6
? Please pick a preset: Manually select features
? Check the features needed for your project:
◉ Babel
◯ TypeScript
◯ Progressive Web App (PWA) Support
❯◉ Router
◯ Vuex
◯ CSS Pre-processors
◯ Linter / Formatter
◯ Unit Testing
◯ E2E Testing

上下键移动光标,空格键选择或取消,回车键下一步

Vue CLI v4.4.6
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, Router

路由模式分为历史模式和hash模式两种,hash模式url中有#号,history没有但需要代码中配置,2版本3版本为hash模式

? Use history mode for router? (Requires proper server setup for index fallback in production) (Y/n) n

配置是放在package中还是指定的配置文件里,按默认走

? Where do you prefer placing config for Babel, ESLint, etc.?
❯ In dedicated config files
  In package.json

以后的模块是否按当前的模式搭建

? Save this as a preset for future projects? (y/N) N

  Successfully created project vue2.
Get started with the following commands: $ cd vue2
$ yarn serve WARN Skipped git commit due to missing username and email in git config.
You will need to perform the initial commit yourself.

启动

$ cd vue2
$ yarn serve
yarn run v1.22.4
$ vue-cli-service serve
INFO Starting development server...
98% after emitting CopyPlugin DONE Compiled successfully in 2084ms 5:26:11 PM App running at:
- Local: http://localhost:8080/
- Network: http://192.168.43.157:8080/ Note that the development build is not optimized.
To create a production build, run yarn build.

2版本的启动方式,进入项目目录,npm run dev

项目文件:

$ ll
total 384
drwxrwxr-x 6 tanpengfei3 tanpengfei3 4096 6月 27 17:25 ./
drwxrwxr-x 4 tanpengfei3 tanpengfei3 4096 6月 27 17:24 ../
-rw-rw-r-- 1 tanpengfei3 tanpengfei3 73 6月 27 17:25 babel.config.js
-rw-rw-r-- 1 tanpengfei3 tanpengfei3 30 6月 27 17:25 .browserslistrc
drwxrwxr-x 7 tanpengfei3 tanpengfei3 4096 6月 27 17:25 .git/
-rw-rw-r-- 1 tanpengfei3 tanpengfei3 230 6月 27 17:25 .gitignore
drwxrwxr-x 758 tanpengfei3 tanpengfei3 28672 6月 27 17:26 node_modules/
-rw-rw-r-- 1 tanpengfei3 tanpengfei3 436 6月 27 17:25 package.json
drwxrwxr-x 2 tanpengfei3 tanpengfei3 4096 6月 27 17:25 public/
-rw-rw-r-- 1 tanpengfei3 tanpengfei3 263 6月 27 17:25 README.md
drwxrwxr-x 6 tanpengfei3 tanpengfei3 4096 6月 27 17:25 src/
-rw-rw-r-- 1 tanpengfei3 tanpengfei3 321757 6月 27 17:25 yarn.lock

node_modules通常不提交git,其他的文件都可以提交

public 存放公共资源,比如图片

src 源代码

package.json 项目依赖的文件

yarn.lock 文件备份

README.md 说明文档

babel.config.js 之前安装的babel ES转码器配置

package.json文件

{
"name": "vue2",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build"
},
"dependencies": {
"core-js": "^3.6.5",
"vue": "^2.6.11",
"vue-router": "^3.2.0"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.4.0",
"@vue/cli-plugin-router": "~4.4.0",
"@vue/cli-service": "~4.4.0",
"vue-template-compiler": "^2.6.11"
}
}

serve 启动命令

build 编辑打包

依赖的vue版本是2.6,vue-router版本是3.2

$ ll src/
total 32
drwxrwxr-x 6 tanpengfei3 tanpengfei3 4096 6月 27 17:25 ./
drwxrwxr-x 6 tanpengfei3 tanpengfei3 4096 6月 27 17:25 ../
-rw-rw-r-- 1 tanpengfei3 tanpengfei3 526 6月 27 17:25 App.vue
drwxrwxr-x 2 tanpengfei3 tanpengfei3 4096 6月 27 17:25 assets/
drwxrwxr-x 2 tanpengfei3 tanpengfei3 4096 6月 27 17:25 components/
-rw-rw-r-- 1 tanpengfei3 tanpengfei3 175 6月 27 17:25 main.js
drwxrwxr-x 2 tanpengfei3 tanpengfei3 4096 6月 27 17:25 router/
drwxrwxr-x 2 tanpengfei3 tanpengfei3 4096 6月 27 17:25 views/

main.js 是项目入口文件

App.vue 是一个组件,项目入口的组件,以大写字母开头,后缀.vue

router 路由

assets 静态资源,CSS / 字体  / 图片

views 展示的组件视图

components 组件,这里面放的是可以作为其他.vue后缀文件中组件使用的组件。模板中components放的是HelloWorld.vue,views/Home.vue中的使用

<template>
<div class="home">
<img alt="Vue logo" src="../assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App"/>
</div>
</template> <script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue' export default {
name: 'Home',
components: {
HelloWorld
}
}
</script>

通过一个<HelloWorld/>标签来使用

vue项目本质上是一个Node.js项目,不同于其他的web项目根目录看到index.html,main.html之类的主页,这类项目的主页是main.js。

本质上他们都一样,都是html dom + js +css的组合文件,不同的是,之前的web项目更像是在html中引入了js和css,而node.js则是在js文件中引入了html dom,并通过js实现了一个轻量的事件驱动请求/响应服务器。这个服务器的存在,让node.js项目与之前的web+额外的服务器的方式有了很大的区别,这使得js的地位大增。实际上Js是一种语言,可以写各种软件,甚至是数据库,而html dom只是一种标识,无疑Js的功能要强大的多,以此为主导并无不妥。

main.js文件中引入了路由,初始化了Vue对象,引入了其他组件,成为了项目的入口。

vue-cli4脚手架搭建一的更多相关文章

  1. 使用Vue CLI脚手架搭建vue项目

    本次是使用@vue/cli 3.11.0版本搭建的vue项目 1. 首先确保自己的电脑上的Node.js的版本是8.9版本或者以上 2. 全局安装vue/cli npm install @vue/cl ...

  2. 用 vue cli 脚手架搭建单页面 Vue 应用(进阶2)

    1.配置 Node 环境. 自行百度吧. 安装好了之后,打开 cmd .运行 node -v .显示版本号,就是安装成功了. 注:不要安装8.0.0以上的版本,和 vue-cli 不兼容. 我使用的 ...

  3. vue+webpack4 脚手架搭建

    1, vue 中 h => h(App) 的含义: //render: h => h(App) 是下面内容的缩写: render: function (createElement) { r ...

  4. 13. Vue CLI脚手架

    一. Vue CLI 介绍 1. 什么是Vue CLI? Vue CLI 是一个基于 Vue.js 进行快速开发的完整系统.Vue CLI 致力于将 Vue 生态中的工具基础标准化.它确保了各种构建工 ...

  5. 让vue-cli脚手架搭建的项目可以处理vue文件中postcss语法

    图中&属于postcss的语法,这样书写样式可以清楚的看出选择器之前的层级关系,非常好用. 在利用vue-cli脚手架搭建的项目中如果不配置是不支持这种写法的,这样写不会报错,但是样式不生效. ...

  6. 用vue-cli脚手架搭建一个仿网易云音乐的全家桶vue项目

    一,vue-cli环境搭建 1,全局安装webpack npm install webpack -g 2,安装vue脚手架 npm install vue-cli -g 3,新建一个新的project ...

  7. vue脚手架搭建流程

    搭建vue项目之前你需要安装vue的脚手架和node.js,一起去看看怎么搭建一个vue环境吧.(学编程语言最爱看见的就是用这个先写一个helloworld,只想说我对世界友好可是现实是残酷的.... ...

  8. 从0开始搭建vue+webpack脚手架(三)

    在从0开始搭建vue+webpack脚手架(二)中已经基本完成了开发环境的配置.当开发完成后,我们需要将完成的项目进行打包,接下来对打包做一些优化: 运行 $ npm run build 可生成dis ...

  9. 从0开始搭建vue+webpack脚手架(二)

    接着从0开始搭建vue+webpack脚手架(一) 三.配置webpack-dev-server 1. webpack-dev-server自带一个node的服务器, 项目在服务端运行的同时可以实现热 ...

  10. 脚手架搭建vue框架

    一. node安装 1)如果不确定自己是否安装了node,可以在命令行工具内执行: node -v  (检查一下 版本): 2)如果 执行结果显示: xx 不是内部命令,说明你还没有安装node , ...

随机推荐

  1. RedHat 7.0 下 FTP 服务的安装,启动,配置,以及虚拟用户的建立

    (注意! 区分shell命令和往配置文件里加的代码不同) 一:ftp服务的安装,启动和启用.   1:vim /etc/sysconfig/selinux     改为disabled后重启     ...

  2. Node.js躬行记(14)——压力测试

    公司有个匿名聊天的常规H5界面,运营向做一次 50W 的推送,为了能配合她的计划,需要对该界面做一次压力测试. 一.JMeter 压测工具选择了JMeter,这是Apache的一个项目,它是用Java ...

  3. Java测试开发--HttpClient常规用法(九)

    1.HttpClient可以读取网页(HTTP/HTTPS)内容 2.对url发送get/post请求(带不带参数都可以),进行测试 一.maven项目pom.xml需要引入包 <depende ...

  4. ES6-字符串-模板字符串(复习+学习)

    昨天学习了字符串对象和字符串的表示,就是利用utf-8等不同的编码方式,还有许多的对象方法,都是处理字符串的方法,挺方便的,今天我学习了一下字符串模板,这里记录i一下学习的笔记,当然,今天学习了部分内 ...

  5. PTA二叉搜索树的操作集 (30分)

    PTA二叉搜索树的操作集 (30分) 本题要求实现给定二叉搜索树的5种常用操作. 函数接口定义: BinTree Insert( BinTree BST, ElementType X ); BinTr ...

  6. celery kill task

    from celery.task.control import revokerevoke(task_id, terminate=True) https://stackoverflow.com/ques ...

  7. layui 如果调用 from 内嵌入的 iframe子页面方法

    (人笨,占时想法的办法,不要骂,不要骂,怕了怕了,想到别的会来改的) 父页面; <%@ page language="java" contentType="text ...

  8. node对象

    global,node的全局对象;js在游览器中的全局对象为windows 在node环境中;输入global.consloe 输出: Console { log: [Function: bound ...

  9. [Aizu1410]Draw in Straight Lines

    注意到当操作确定后,显然操作顺序总是涂黑色的1操作->涂白色的1操作->2操作 用$b/w_{r/c}(i,j)$表示$(i,j)$是否被黑色/白色 横着/竖着 涂过(1表示涂过,0表示没 ...

  10. [bzoj3170]松鼠聚会

    这个距离就是切比雪夫距离,有一个神奇的东西是说将(x,y)变成(x+y,x-y),然后就是曼哈顿距离,因此转化后对x坐标和y坐标分别统计排序和求和(求前缀和预处理+二分) 1 #include< ...