"tabBar": { "selectedColor": "#000000", "backgroundColor": "#ffffff", "color": "#c7c7c7", "list": [ { "selectedIconPath": "/images/tab/classic@highlight.png", "pagePath": "pages/classic/classic", "text": "流行", "iconPath": "/images/tab/classic.png" }, { "selectedIconPath": "/images/tab/book@highlight.png", "pagePath": "pages/book/book", "text": "书籍", "iconPath": "/images/tab/book.png" }, { "selectedIconPath": "/images/tab/my@highlight.png", "pagePath": "pages/my/my", "text": "喜欢", "iconPath": "/images/tab/my.png" } ]}
可以应用esLint,在github上aribnb的项目里
- 对象简写
var a = 1//badthis.setData({ a: a})//goodthis.setData({ a})
- 方法简写
method:{ //bad add: function(){ ... } //good add(){ ... }}
- 能用const尽量不要用let,能用let不要用var
纯粹回调会陷入回调地狱,剥夺函数return的能力
promise 多个异步函数合并,不需要层层传递callback
async await 最佳处理异步方式,小程序不支持
本质
? Promise是一个对象,可以用来保存状态。它的状态有 padding,fulfilled,rejected,状态一点修改就 凝固了。即已成功不能改成已失败,过程也是不可逆的。
用法
//封装微信的request方法http里的代码export default class Http{ request(){ return new Promise((resolve,reject)=>{ _request(...); }) } _request(url,resolve,reject,data={},method="GET"){ resolve(...); reject(...) }}//classicModel里调用import Http from '../utils/http'class ClassicModel extends Http{ this.request(...).then(res=>{...}).catch(err>{...});}