运行一下几句代码,立马就能理解async/await怎么使用了:
testAsync: async function () {
let res = await wx.showModal({ content: 'step1?' })
if (res.confirm) { } else return
await this.step1()
res = await wx.showModal({ content: 'step2?' })
if (res.confirm) { } else return
await this.step2()
console.log('end')
},
step1: async function () {
await wx.showModal({ content: 'this is step1' })
console.log('end of step1')
},
step2: async function () {
let res = await wx.showActionSheet({
itemList: ['A', 'B'],
}).catch(err => console.log('err:', err))//catch可以防止阻断
if (res.tapIndex == 0) { console.log('A') }
if (res.tapIndex == 1) { console.log('B') }
console.log('end of step2')
},
监听: php artisan make:observer NoticeObserver -m Models/Notice public function created(Comment $comment){ // dispatch(new NoticeJob()); Log::info('评论点赞成功'); }// 使用laravel提供模型类初始方法 protected static function boot() { parent::boot(); //注册自定义观察类 self::observe(NoticeObserver::class); }