1. 箭頭函數
不是箭頭函數的 success (res) {}
onLoad: function () {
//查看是否授權
wx.getSetting({
success(res) {
if (res.authSetting['scope.userInfo']) {
// 已經授權,可以直接調用 getUserInfo 獲取頭像暱稱
wx.getUserInfo({
success: function (res) {
console.log(res.userInfo)
}
})
}else{
console.log("沒授權!")
}
}
})
},
是箭頭函數的 success: (res) => {}
onLoad: function () {
//查看是否授權
wx.getSetting({
success: (res) => {
if (res.authSetting['scope.userInfo']) {
// 已經授權,可以直接調用 getUserInfo 獲取頭像暱稱
wx.getUserInfo({
success: function (res) {
console.log(res.userInfo)
}
})
}else{
console.log("沒授權!")
}
}
})
},
2. 開發小技巧,保存後停留在當前頁面
每次保存後,都跳轉到 index.頁面
開發時,把正在開發的頁面放在第一個
{
"pages": [
"pages/index/index",
"pages/second/index",
"pages/logs/logs",
"pages/share/share",
],
3. 在 WebStorm 寫微信小程序
防止 wxml,wxss 文件報錯
Settings — Editor — File Types
- 在 CSS(Cascading Style Sheet) 添加 *.wxss
- 在 HTML 添加 *.wxml