内容简介:1.在微信小程序项目添加package.json文件或者直接npm init.2.在package.json中添加regenerator包和版本`"devDependencies": {
1.在微信小程序项目添加package.json文件或者直接npm init.
2.在package.json中添加regenerator包和版本
`"devDependencies": {
"regenerator":"0.13.3"}`
3.微信开发者工具-》工具-》npm构建
4.在需要使用async/await语法的文件引入regeneratorRuntime
const regeneratorRuntime = require('regenerator-runtime')
5.使用async/await语法
lifetimes: {
attached:async function(){
// 在组件实例进入页面节点树时执行
let data= await req(this.properties.apiType);
console.log(data)
},
detached() {
// 在组件实例被从页面节点树移除时执行
},
},
需要注意this的指向,比如生命周期如果用箭头函数会丢失this
或者直接这样
lifetimes: {
async attached(){
// 在组件实例进入页面节点树时执行
let data= await req(this.properties.apiType);
console.log(data)
},
async detached() {
// 在组件实例被从页面节点树移除时执行
},
},
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Fluent Python
Luciano Ramalho / O'Reilly Media / 2015-8-20 / USD 39.99
Learn how to write idiomatic, effective Python code by leveraging its best features. Python's simplicity quickly lets you become productive with it, but this often means you aren’t using everything th......一起来看看 《Fluent Python》 这本书的介绍吧!