zarknight / wxapp-startkit Goto Github PK
View Code? Open in Web Editor NEW微信小程序 StartKit
微信小程序 StartKit
我实际的使用过程中发现,不仅仅是 bind 方法需要定义为属性后才能被使用,即便是普通的自定义实例方法也需要这么做才可以。
通过控制台我发现,是因为当微信小程序在执行页面的生命周期回调方法时,所获得的 this 也就是 Page 实例中,是没有任何通过函数定义的方法的,只有属性定义的方法。
new class IndexPage {
data = {
userInfo: {},
greeting: 'Hello,World'
}
///////////////////////////////////////////////////////////////////////////
constructor() {
Page(this)
}
onLoad() {
console.log(">>> page:onLoad", app)
userService.getUserInfo().then((userInfo) => {
this.setData({userInfo: userInfo})
}).catch((e) => {
console.log(e);
})
}
onReady() {
console.log(">>> page:onReady")
}
onShow() {
console.log(">>> page:onShow")
this.instance_method_1() // failed instance_method_1 undefined
this.instance_method_2() // success
}
onHide() {
console.log(">>> page:onHide")
}
onUnload() {
console.log(">>> page:onUnload")
}
onPullDownRefresh() {
console.log(">>> page:onPullDownRefresh")
}
///////////////////////////////////////////////////////////////////////////
// 普通的方法调用时,通过定义方法的方式将不会被检测到,
// 必须以定义属性的方式才能被检测到:
///////////////////////////////////////////////////////////////////////////
instance_method_1() {
}
instance_method_2 = () => {
}
///////////////////////////////////////////////////////////////////////////
// 微信小程序(WAService.js)用hasOwnProperty进行bind的事件处理函数检测,
// 通过定义方法的方式将不会被检测到,必须以定义属性的方式才能被检测到:
///////////////////////////////////////////////////////////////////////////
onButtonTap = () => {
console.log(">>>>>> button tapped")
util.wxPromisify(wx.setStorage)({
key: "abc",
data: "11111"
}).then((res) => {
console.log(">>>>>>>> result:", res)
}).catch((res) => {
console.error(">>>>>>> error:", res)
})
}
onViewTap = () => {
wx.navigateTo({url: '../settings/settings'})
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.