带参数跳转,用data-id传id参数过去,读取的时候id是有,但是undefined报错
onLoad:function (options) {
console.log("options携带的值:",options)
let id=options.id
console.log("取id",id)
wx.cloud.database().collection("goods")
.doc(id)
.get()
.then( res =>{
this.setData({
item: res.data
})
})
.catch( err=> {
})
options携带的值: {id636050766253fa970542057a1f67ffa4: "undefined"}
demo1-1.js? [sm]:10 取id undefined
WAServiceMainContext.js:2 Error: collection.doc:fail -1 . docId must not be empty
at S (WASubContext.js?t=wechat&s=1649697738278&v=2.23.4:2)
at E (WASubContext.js?t=wechat&s=1649697738278&v=2.23.4:2)
at Object.doc (WASubContext.js?t=wechat&s=1649697738278&v=2.23.4:2)
at Mi.onLoad (demo1-1.js? [sm]:12)
at Mi. (WASubContext.js?t=wechat&s=1649697738278&v=2.23.4:2)
at Mi.i.callPageLifeTime (WASubContext.js?t=wechat&s=1649697738278&v=2.23.4:2)
at jt (WASubContext.js?t=wechat&s=1649697738278&v=2.23.4:2)
at WASubContext.js?t=wechat&s=1649697738278&v=2.23.4:2
at Wt (WASubContext.js?t=wechat&s=1649697738278&v=2.23.4:2)
at r. (WASubContext.js?t=wechat&s=1649697738278&v=2.23.4:2)(env: Windows,mp,1.05.2203251; lib: 2.23.4)
每一步都用console看了,完全没头绪,传之前好好的,传过去就undefined了
不知道哪一步错了
问题还是出在你传数据的那里了,你把你传数据那里发一下
对比下DOM的写法和JS的写法,一下两种方式都可正常接收到参数。
传参方式:
页面A传页面B
DOM
<navigator url='/pages/index/index?id={{id}}' hover-class='none' > </navigator>
等同js wx.navigateTo、wx.redirectTo跳转的传参:
wx.navigateTo({
url: '/pages/index/index?id='+id,
})
页面B接收
onLoad: function (option) {
var that = this;
if (option.id) {
this.id= option.order_id;
}
}
本页面DOM 传给本js ‘data-自定义’
DOM
<view class="action_right" bindtap="phoneCall" data-value="{{user.mobile}}">
<text>电话咨询</text>
</view>
JS
//拨号
phoneCall: function (e) {
var mobile = e.currentTarget.dataset.value;
var that=this
if (mobile) {
wx.makePhoneCall({
phoneNumber: mobile
})
}
}