zhengwei1949 / myblog

个人博客
10 stars 6 forks source link

流行框架课程重难点复习 #92

Open zhengwei1949 opened 6 years ago

zhengwei1949 commented 6 years ago

流行框架课程重难点总复习

tips

git

为什么要学习git

概念

git操作流程

  1. 初始化仓库 git init
  2. 配置用户信息:
    • 配置用户名:git config --global user.name "xxx"
    • 配置邮箱: git config --global user.email "xm@sina.com"
  3. 把代码添加到暂存区
    • git add 项目路径
  4. 将暂存区的代码提交到仓库
    • git commit -m "这是对这次添加的东西的说明"
  5. 将代码提交到远程服务器
    • git push [地址] master

常用命令

tips

npm

为什么要学习npm

概念

常用命令

gulp

为什么要学习gulp

常见api

常见插件

代码示例参考

var gulp = require('gulp');//引入gulp库
var uglify = require('gulp-uglify');//因为我们下面要压缩js,所以,这里面引入gulp-uglify插件
gulp.task('ceshi',function(){//创建一个任务,名字叫ceshi
    gulp.src('./a.js')//指定我们要处理什么文件
        .pipe(uglify())//使用uglify插件
        .pipe(gulp.dest('./dist'));//指定我们要处理的文件处理好之后放到哪里
})

angular

为什么要学习angular

angular理解

书写angular.js代码的步骤

  1. 引入angular库
  2. 通过ng-app="myApp"指定angular管理的范围,并且通过angular.module('myApp',[])
  3. 通过ng-controller和myApp.controller指定控制器的管理范围
  4. 建模:根据页面结构,抽象出具体的数据模型
  5. 根据页面中的事件的触发形式和触发的时机,绑定对应的事件
  6. 在$scope上面写具体的事件触发后的逻辑

对mvc的理解

对mvvm的理解

+ mvvm和mvc的区别
    1. mvc : 不管什么操作要通过控制器
    2. mvvm: 视图和$scope上的数据是双向数据绑定的,并不需要经过什么控制器

对模块化的理解

1. 参考https://github.com/zhengwei1949/module

常见内置指令

创建控制器的四种方式

var myApp = angular.module('myApp',[]);
myApp.controller('myController',function($scope){

})
function myController($scope){

}
var myApp = angular.module('myApp',[]);
myApp.controller('myController',function(){
    this.name = 'xiao ming';
})
var myApp = angular.module('myApp',[]);
myApp.controller('myController',['$scope',function($scope){

}])

自定义指令常见属性

过滤器

<li ng-repeat="item in data | filter : true">
{{item.name}}
</li>
+ 精确匹配
<li ng-repeat="item in data | filter : {completed:true}">
{{item.name}}
</li>

实现计算器的N种思路

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body ng-app="myApp" ng-controller="myController">
    <input type="text" ng-model="A">+
    <input type="text" ng-model="B">
    <input type="button" value="=" ng-click="add()">
    <input type="text" ng-model="result">
    <script src="./angular.js"></script>
    <script>
    var myApp = angular.module('myApp',[])
    myApp.controller('myController',function($scope){
        $scope.A = 0;
        $scope.B = 0;
        $scope.add = function(){
            $scope.result = ($scope.A - 0) + ($scope.B - 0);
        }
    })
    </script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body ng-app="myApp" ng-controller="myController">
    <input type="text" ng-model="A">+
    <input type="text" ng-model="B">
    <p>{{(A-0) + (B-0)}}</p>
    <script src="./angular.js"></script>
    <script>
    var myApp = angular.module('myApp',[])
    myApp.controller('myController',function($scope){
        $scope.A = 0;
        $scope.B = 0;
    })
    </script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body ng-app="myApp" ng-controller="myController">
    <input type="text" ng-model="A">+
    <input type="text" ng-model="B">
    <p ng-bind="(A-0) + (B-0)"></p>
    <script src="./angular.js"></script>
    <script>
    var myApp = angular.module('myApp',[])
    myApp.controller('myController',function($scope){
        $scope.A = 0;
        $scope.B = 0;
    })
    </script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body ng-app="myApp" ng-controller="myController">
    <input type="text" ng-model="A">+
    <input type="text" ng-model="B">
    <p ng-bind="getResult()"></p>
    <script src="./angular.js"></script>
    <script>
    var myApp = angular.module('myApp',[])
    myApp.controller('myController',function($scope){
        $scope.A = 0;
        $scope.B = 0;
        $scope.getResult = function(){
            return ($scope.A - 0) + ($scope.B - 0);
        }
    })
    </script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body ng-app="myApp" ng-controller="myController">
    <input type="text" ng-model="A">+
    <input type="text" ng-model="B">
    <p>{{getResult()}}</p>
    <script src="./angular.js"></script>
    <script>
    var myApp = angular.module('myApp',[])
    myApp.controller('myController',function($scope){
        $scope.A = 0;
        $scope.B = 0;
        $scope.getResult = function(){
            return ($scope.A - 0) + ($scope.B - 0);
        }
    })
    </script>
</body>
</html>

监视$watch

服务(service)

myApp.server('myService',[function(){
    this.name = 'itcast';
}]);

myApp.controller('myController',['$scope','myService',function($scope,myService){
    console.log(myService.name);
}])

todoMVC思路

前期训练

思维模式

书写代码步骤及思路

  1. 项目初始化

    • 下载项目

    ``git clone https://github.com/tastejs/todomvc-app-template.git

    • 安装依赖的js,css
        cnpm install
    • 去掉用不上的代码:把base.css,base.js去掉
  2. 展示任务

  3. 添加任务

  4. 删除任务

  5. 修改任务内容

    • 前期我们不用想太多,自然会想到和删除类似,要传一个id进去
    • 接着我们结合之前做过的简版todoMVC思考,如何实现编辑效果
    • 其实是通过ng-class来实现的,要传入一个布尔值
    • 这个布尔值如果写死成true或false,则达不到我们的目的,我们每一次只能同时有一个是在编辑状态
    • 这时候思考:我们每一列的id其实是不一样的,我们可以考虑搞一个变量,让这个变量的值等于这个id,这样做判断表达式的时候,就能出来一个true和一堆的false
    • 效果实现之后,最后再想,一开始的情况下所有的处于未编辑状态,所以我们初始的时候就把这个变量设置成-1
  6. 切换任务状态

  7. 批量切换任务状态

  8. 显示未完成的任务数

  9. 清除所有已完成任务

为什么要从后往前删的理解

//思考:为什么不能把6删除掉??????
var arr = [1,4,6,9];
for(var i=0;i<arr.length;i++){
    if(arr[i]%2 === 0){
        arr.splice(i,1);
    }
}
console.log(arr);
  1. filter过滤器实现切换不同状态任务的显示

  2. 切换不同状态焦点状态样式的操作

  3. 使用$watch重构all,active,completed这块的代码

  4. 使用service进行重构代码(这块了解即可)

路由

豆瓣项目思路

  1. 项目模板划分方式
  2. 首页模块功能
  3. 正在热映、即将上映、top250模块结构搭建
  4. 假数据绑定
  5. 正在热映(通过ajax请求得到数据)
  6. angular使用jsonp请求豆瓣数据(封装jsonp方法的service)
  7. 通过点击事件来获取分页数据
  8. 分页完善
  9. 即将上映
  10. top250功能
  11. 合并重复的功能
  12. 设置loading动画
  13. 切换导航栏焦点状态
  14. 详情页
  15. 搜索功能

考试注意事项