Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

### vue-cli学习内容 #7

Open
huangchucai opened this issue Jun 20, 2017 · 0 comments
Open

### vue-cli学习内容 #7

huangchucai opened this issue Jun 20, 2017 · 0 comments

Comments

@huangchucai
Copy link
Owner

  1. vue.js框架介绍
  2. vue-cli 脚手架 搭建基本代码框架
  3. vue-router 管理插件管理路由
  4. vue-resource Ajax通信
  5. webpack 搭建工具
  6. es6+eslint eslint:es6代码风格检查工具
  7. 工程化 组件化 模块化
  8. 移动端常见的开发技巧
    • flex弹性布局
    • css stickyfooter
    • 酷炫的交互设计

1. vue.js介绍

  • Vue-cli是vue的脚手架工具

    1. 目录结构
    2. 本地调试
    3. 代码部署
    4. 热加载
    5. 单元测试
  • vue-cli的文件夹和文件分析

    • build/config 文件夹 webpack配置相关

    • node_modules npm包安装依赖

    • src 存放的项目源码

    • static 第三方静态资源 .gitkeep 当文件夹为空的时候也提交到github仓库

    • .babelrc babel转换

      // babel的配置文件
      {
        "presets": ["es2015", "stage-2"],  //预设插件,es2015babel预设需要安装的插件  stage-(0-3) 
        "plugins": ["transform-runtime"], //装换es6
        "comments": false  //不支持注释
      }
      
    • .editorconfig 编辑器设置

      root = true
      
      [*]
      charset = utf-8
      indent_style = space  //缩减方式  空格
      indent_size = 2
      end_of_line = lf
      insert_final_newline = true
      trim_trailing_whitespace = true
    • .eslintignore 忽略eslint检查文件

      build/*.js
      config/*.js
      
      // 忽略build和config文件的检查
    • .eslintrc.js eslint配置

      module.exports = {
        root: true,
        parser: 'babel-eslint',
        parserOptions: {
          sourceType: 'module'
        },
        // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
        extends: 'standard',
        // required to lint *.vue files
        plugins: [
          'html'
        ],
        // add your custom rules here  修改规则  配置为0的话就是不用这个规则
        'rules': {
          // allow paren-less arrow functions
          'arrow-parens': 0,
          // allow async-await
          'generator-star-spacing': 0,
          // allow debugger during development
          'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0  //开发环境允许debugger,正式环境不可以
        }
      }
    • .gitignore 提交的时候忽略的目录

    • index.html 入口文件

  • 代码编译过程

    1. 路口文件index.html

      <!DOCTYPE html>
      <html>
        <head>
          <meta charset="utf-8">
          <title>sell</title>
        </head>
        <body>
          <app></app>  
          <!-- built files will be auto injected -->
        </body>
      </html>
      <!-- js和css动态的插入到页面  -->
    2. main.js 入口js文件 src下面的main.js

      import Vue from 'vue'    
      import App from './App'   // ./App.vue
      
      /* eslint-disable no-new */
      new Vue({
        el: 'body',  //挂载点
        components: { App }  //es6简写 { App : App}  components 注册当前页面注册标签
      })
    3. App.vue模块

      每一个组建分三个部分 1. template 2. script 3. style

      <template>
        <div id="app">
          <img class="logo" src="./assets/logo.png">
          <hello></hello>  <!--下面的script components定义了自定义的标签-->
          <p>
            Welcome to your Vue.js app!
          </p>
          <p>
            To get a better understanding of how this boilerplate works, check out
            <a href="http://vuejs-templates.github.io/webpack" target="_blank">its documentation</a>.
            It is also recommended to go through the docs for
            <a href="http://webpack.github.io/" target="_blank">Webpack</a> and
            <a href="http://vuejs.github.io/vue-loader/" target="_blank">vue-loader</a>.
            If you have any issues with the setup, please file an issue at this boilerplate's
            <a href="https://github.com/vuejs-templates/webpack" target="_blank">repository</a>.
          </p>
          <p>
            You may also want to checkout
            <a href="https://github.com/vuejs/vue-router/" target="_blank">vue-router</a> for routing and
            <a href="https://github.com/vuejs/vuex/" target="_blank">vuex</a> for state management.
          </p>
        </div>
      </template>
      
      <script>
      import Hello from './components/Hello'
      
      export default {
        components: {
          Hello  <!-- 定义<hello></hello>标签 -->
        }
      }
      </script>
      
      <style>
      html {
        height: 100%;
      }
      
      body {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100%;
      }
      
      #app {
        color: #2c3e50;
        margin-top: -100px;
        max-width: 600px;
        font-family: Source Sans Pro, Helvetica, sans-serif;
        text-align: center;
      }
      
      #app a {
        color: #42b983;
        text-decoration: none;
      }
      
      .logo {
        width: 100px;
        height: 100px
      }
      </style>
      // hello.vue
      <template>
        <div class="hello">
          <h1>{{ msg }}</h1>
        </div>
      </template>
      
      <script>
      // 导出模块 vue会处理导出相应的样式,模版,数据 
      export default {
        data () {
          return {
            msg: 'Hello Vue!'
          }
        }
      }
      </script>
      
      <!-- Add "scoped" attribute to limit CSS to this component only -->
      <style scoped>
      h1 {
        color: red;
      }
      </style>

@huangchucai huangchucai changed the title ### vue.js学习内容 ### vue-cli学习内容 Aug 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant