1.開發小程序發送請求時,報錯不在如下合法列表中:javascript
在開發工具詳情中設置:html
請參考微信官方文檔:關於小程序網絡相關API說明java
2.若是你須要權限驗證(如登陸後訪問),小程序不像瀏覽器能幫你自動攜帶cookie信息,那麼你須要本身寫在將cookie寫入請求hedear中,否則每次請求都通不過權限驗證。json
wx.request({ url: `${API_URL}/${type}`, data: Object.assign({}, params), method: 'POST', header: { 'cookie': wx.getStorageSync('cookie')[0], 'Content-Type': 'application/json', 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8' }, success: function(res){ wx.hideLoading(); if (res.header['Set-Cookie']) { //提取cookie,保存到storage中 var setCookie = res.header['Set-Cookie'].replace(new RegExp('Path=/'), '').split(',') console.log('cookies:' + setCookie); }
}
})
3.小程序下載文件保存本地,須要配置可信域名和https,而且下載的文件根本在手機獲取不到。小程序
4.打開頁面過多致使內存佔用太高。api
globalJump: function (url) { var pageLevel = getCurrentPages().length; if (typeof url == 'string') { url = url } else { url = url.currentTarget.dataset.url; } if (pageLevel < 4) { wx.navigateTo({ url: url }) } else { wx.redirectTo({ url: url }); } }
5. 頁面滾到底部加載數據瀏覽器
不要使用scrollview。使用Page中的onReachBottom微信
6. 頁面內使用setTimeIntervar跳轉後定時器不會關閉致使報錯cookie
使用外部方法,判斷頁面是否已經跳轉網絡
7.用戶受權(查看文檔,更改了用法)
使用舊的方法在開發者工具會提示你使用button組件(已經上線會兼容舊的寫法)
注意:此接口有調整,使用該接口將再也不出現受權彈窗,請使用 <button open-type="getUserInfo"></button> 引導用戶主動進行受權操做
wx.authorize({scope: "scope.userInfo"}),沒法彈出受權窗口,請使用 <button open-type="getUserInfo"></button> .
彩蛋:須要在真機上測試能夠點擊預覽也能夠上傳爲開發版本。
-----原創文章,©版權全部,轉載請註明標明出處:http://www.cnblogs.com/doinbean