导 : 以前注册组件有什么缺点 ?javascript
1- 缺少语法高亮 2-格式很差总体 3-没有专门的写css代码等等css
参考 : vue => 工具 => 单文件组件html
脚手架 2.X ==> 2.Xvue前端
脚手架 3.X ==> 3.X vuevue
vue-cli 是 vue 的脚手架工具java
做用 : vue-cli 提供了一条命令, 咱们直接经过这条命令就能够快速的生成一个 vue 项目 (vue init XX
) 。 项目的基本结构、以及 webpack 配置项 所有配置 好了node
为何会有脚手架工具 ???webpack
由于 webpack 配置繁琐, 阻止一批想用 vue 可是不会 webpack 的开发人员,因此做者直接将全部 vue 项目中用到的配置所有帮你写好了,这样,就不须要开发人员再去配置基础 webpack 配置项了git
也就是说,使用 vue-cli 这个脚手架工具后,不再用担忧 webpack 配置问题了, 咱们前端只须要写 vue 代码, 来实现功能便可es6
npm i -g vue-cli
vue init webpack 项目名称
vue init webpack vue-demo01
? Project name # 回车
? Project description # 回车
? Author # 回车
? Vue build standalone # => 运行时+编译 => 详见下面的问题1
? Install vue-router? # Yes
(建议手动装)
? Use ESLint to lint your code? # Yes => 详见下面的问题2
? Pick an ESLint preset Standard # standard
? Set up unit tests # No
? Setup e2e tests with Nightwatch? # No
? Should we run `npm install` for you after the project has been created? # (recommended) npm
复制代码
(总结:有test就n)
To get started:
cd vue-demo01
npm run dev
复制代码
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
第一遍:文件夹, 第二遍再细化文件
# build - webpack 相关配置
- build.js - 生产环境构建代码
- check-version.js 检查 node、npm 等版本
- util.js 构建工具相关
- vue-loader.config.js vue-loader 的配置文件
- webpack.base.conf.js - webpack 的基础配置
- webpack.dev.conf.js - webpack 开发环境配置
- webpack.prod.conf.js - webpack 发布环境配置
# config - vue 基本配置文件(好比:监听端口(17), 使用 eslint:(26))
- dev.env.js - 开发环境变量
- index.js 项目的一些配置
- prod.env.js 生成环境变量
# node_modules - node 安装的依赖包
# src - 资源文件夹, 之后咱们就在这个目录下写代码
- assets - 静态资源 (图片 css 都放在这)
- components - 公用组件
- router - 路由
- App.vue - 项目的根组件
- main.js - 项目的入口文件(总逻辑)
# static - 静态资源 (图片 json 数据之类的)
- .gitkeep git 保持文件,由于 git 上传,会忽略空文件夹
# .babelrc - babel 配置文件, (es6 语法编译配置,将 es6 转化为浏览器可以识别的代码)
# .editorconfig - 定义代码格式
- charset = utf-8 编码 utf8
- indent_style = space 缩进 空格
- indent_size = 2 缩进字符
- end_of_line = lf 回车做为换行的标记
- insert_final_newline = true 最近一空白行做为结尾
- trim_trailing_whitespace = true 清除最开始的空白
- 若是使用 ?
- 1. 安装 vscode 的 editorConfig for vscode
- 2. eslint 检测修复后
# .eslintignore - eslint 检测忽略的地方
- /build/
- /config/
- /dist/
- /\*.js 根目录下带.js 的
# .eslintrc.js - eslint 的配置文件
# .gitignore - git 的忽略文件
# .postcssrc.js - css 配置文件 (啥也没有处理)
# index.html - 页面入口
# package.json - 项目配置文件
复制代码
assets 静态资源
components 组件
App.vue 根组件 => 指定路由出口
app 中的 #app 仍是 index.html 中的 #app, app.vue 中的会覆盖前者 能够经过分别添加 title 属性验证一下
路由出口要写在 app.vue 组件模板中
main.js
Vue.config.productionTip = false
不要打印提示new Vue({
el: '#app', // 目标显示
router, // 挂载路由
components: { App }, // 注册组件 App
template: '<App/>' // 模板显示组件 app
})
复制代码
route/index.js => 路由
必定要记住 :Vue.use(Router)
模块化公工程中必定要安装路由插件 .js 就是一个模块
官网里 也提到 https://router.vuejs.org/zh/installation.html
参考 : vue.js => 安装 => 对不一样构建本版本的解释
// 须要编译器
new Vue({
template: '<div>{{ hi }}</div>'
})
// 不须要编译器
new Vue({
render (h) {
return h('div', this.hi)
}
})
复制代码
router/index.js =>
import HelloWorld from '@/components/HelloWorld'
import HelloWorld from 'C:/users/.../src/components/HelloWorld'
复制代码
概念 : ESLint 是在 JavaScript 代码中识别和报告模式匹配的工具,它的目标是保证代码的一致性和避免错误。
在 vscode等编辑工具 中, 能够提示语法错误
在许多方面,它和 JSLint、JSHint 类似,除了少数的例外:
如何使用 eslint ?
"editor.formatOnSave": true, //#每次保存的时候自动格式化
"eslint.autoFixOnSave": true, // #每次保存的时候将代码按eslint格式进行修复
"eslint.validate": [
{ "language": "html", "autoFix": true },
{ "language": "vue", "autoFix": true },
{ "language": "javascript", "autoFix": true },
{ "language": "wpy", "autoFix": true }
],
"prettier.eslintIntegration": true, // #让prettier使用eslint的代码格式进行校验
"prettier.semi": true, //#去掉代码结尾的分号
"prettier.singleQuote": true, //#使用单引号替代双引号
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
"editor.formatOnType": true //#让函数(名)和后面的括号之间加个空格
复制代码
关闭 Eslint :
dev.useEslint
设置为falsenpm run dev
测试 : 删除 main.js 中的 /* eslint-disable no-new */ 关闭后 会报波浪线,可是不会报错了
安装 vscode 插件 Prettier
功能1 : shift + alt + F => 格式化代码
功能2 : 配合 eslint : 见上一个问题的配置
eslint-disable-next-line # 忽略检测下一行 能够使用单行注释/多行注释,其余都是多行注释
eslint-disable # 忽略当前整个文件
eslint-disable no-new # 忽略前面是new开头
复制代码