定义ajax或者异步编码:
路由指的是斜杠开头,或是斜:杠空的:
加上斜杠就可以触发了,在跳转链接的井号上面
![5640239-e3c2005231ed278f.png](https://upload-images.jianshu.io/upload_images/5640239-e3c2005231ed278f.png)
![5640239-6ce552e83be2d675.png](https://upload-images.jianshu.io/upload_images/5640239-6ce552e83be2d675.png)
流程是什么样的?
把format放到模块里,进行定义;
![5640239-fcf149ac63e9c8de.png](https://upload-images.jianshu.io/upload_images/5640239-fcf149ac63e9c8de.png)
![5640239-1657bee1cff6aff3.png](https://upload-images.jianshu.io/upload_images/5640239-1657bee1cff6aff3.png)
在equires里面再引用一个requires
不推荐:避免这种写法:依赖a模块,依赖b模块
接口的地址,可以省略参数:但要写,叫做代码的可读性:从server里面的route。js里面拿来的
![5640239-a622a1425761a08d.png](https://upload-images.jianshu.io/upload_images/5640239-a622a1425761a08d.png)
![5640239-b9cbb75a267a8bc3.png](https://upload-images.jianshu.io/upload_images/5640239-b9cbb75a267a8bc3.png)
代码换行:不要超过八十个字符,要记得换行:代码编辑习惯的 问题:
把数据请求过来,需要进行
es5新语法:
![5640239-f0693af3de26eea6.png](https://upload-images.jianshu.io/upload_images/5640239-f0693af3de26eea6.png)
foreach:返回两个参数:元素,下标
![5640239-eedb728f43ac8319.png](https://upload-images.jianshu.io/upload_images/5640239-eedb728f43ac8319.png)
第三个返回下标的原因,即要用下标去修改他,第三个参数很少使用
![5640239-7857e5b79eec8da5.png](https://upload-images.jianshu.io/upload_images/5640239-7857e5b79eec8da5.png)
循环组合模板的数据:
![5640239-19a6532e9d1ef30f.png](https://upload-images.jianshu.io/upload_images/5640239-19a6532e9d1ef30f.png)
1.把所有清空一遍,在把数据加入进去:.把新东西在加进去
2.第二种:直接替换
![5640239-bfc34f833d488283.png](https://upload-images.jianshu.io/upload_images/5640239-bfc34f833d488283.png)
请求到了URL的地址,判断的数据也是一样的
![5640239-25a7dc4ce9287d0d.png](https://upload-images.jianshu.io/upload_images/5640239-25a7dc4ce9287d0d.png)
![5640239-38fbfbc2cf6eff97.png](https://upload-images.jianshu.io/upload_images/5640239-38fbfbc2cf6eff97.png)
map ,字典,对象,json,集合:
指的是泛型,map 值都Object类型,取出里面的对象需要进行类型转换;使用了泛型就不用转换了,存的什么类型,取出仍是什么类型;
map也有三个参数:
把返回的结果拿回来,组成一个新的数组:
就是给原先的数组再重新赋值了一遍,
map和foreach的区别:
![5640239-0b8dd133a385243c.png](https://upload-images.jianshu.io/upload_images/5640239-0b8dd133a385243c.png)
把专题模板拷贝到group中;
拼接,组合,加到新的dom里面去
![5640239-4f76199b623758f5.png](https://upload-images.jianshu.io/upload_images/5640239-4f76199b623758f5.png)
动态创建元素,然后循环,就不会卡哦;
抽奖
![5640239-22ca28d615d1f302.png](https://upload-images.jianshu.io/upload_images/5640239-22ca28d615d1f302.png)
步骤是一样的,先判断数据是否可用:
![5640239-905ca9a09c449b20.png](https://upload-images.jianshu.io/upload_images/5640239-905ca9a09c449b20.png)
![5640239-9c29f3fdc3c7a1c3.png](https://upload-images.jianshu.io/upload_images/5640239-9c29f3fdc3c7a1c3.png)
把轮播图的代码拿到page.js中,里面的图片是动态
生成的
![5640239-6dab242e7348e278.png](https://upload-images.jianshu.io/upload_images/5640239-6dab242e7348e278.png)
img是数组,怎么放到模块去用啊:data.imgs.foreach
![5640239-8e5bf588b3938488.png](https://upload-images.jianshu.io/upload_images/5640239-8e5bf588b3938488.png)
循环结束的时候
![5640239-a2acf0c615587b62.png](https://upload-images.jianshu.io/upload_images/5640239-a2acf0c615587b62.png)
再格式化一下打印出地址
先准备下标,根据下标找到图片的地址
![5640239-ac3de1cc056fb344.png](https://upload-images.jianshu.io/upload_images/5640239-ac3de1cc056fb344.png)
![5640239-8b460090cd5c8082.png](https://upload-images.jianshu.io/upload_images/5640239-8b460090cd5c8082.png)
把实例化代码延迟,保证能够完成
![5640239-021d85456b88f2b3.png](https://upload-images.jianshu.io/upload_images/5640239-021d85456b88f2b3.png)
![5640239-54ec2f3763b86e49.png](https://upload-images.jianshu.io/upload_images/5640239-54ec2f3763b86e49.png)
怎么判断,node
如果是节点监听,很耗费性能
所以就去定义模块
定义模块的好处: 将一个整体分割到一些不同的组件中,这可以在某种程度上减少它的复杂性
业务逻辑可以随意的变化: