微信小程序采坑

1.tabBar跳转时无法带参数,解决方法:
//search.js
var app = getApp();
Page({
confirm: function(e){
//获取数据,添加到全局
let val = e.detail.value;
app.searchWord = val;
this.jump();
},
jump: function(){
//跳转tabBar
wx.switchTab({
url: ‘…/index/index’,
});
},
});

//index.js
var app = getApp();
Page({
onShow: function(e){
//获取全局数据
let val = app.searchWord;
}
});
//需要传递参数的页面在跳转前将数据添加到app.js里。需要接受参数的页面在onShow方法接受之前添加到app.js的数据。
2.wx.request()使用post方法请求时,还需要加上header,header[content-type]值为application/x-www-form-urlencoded。例:
wx.request({
url: ‘https://a.com/url.php’,
data: {message: 123},
method: ‘POST’,
header: {
‘content-type’: ‘application/x-www-form-urlencoded’
},
success: function(e){
console.log(e)
}
});
3.Do not have onCollectionTap handler in current page: pages/index/index-detail/index-detail. Please make sure that onCollectionTap handler has been defined in pages/index/index-detail/index-detail, or pages/index/index-detail/index-detail has been added into app.json报错
catchtap="onCollectionTap "
在问题出现前,已将该onCollectionTap事件在index-detail.js文件中定义了,同时也已将index-detail路径在app.json中配置了,
最后发现多了个空格。

你可能感兴趣的:(微信小程序)