杭州网站关键词排名,wordpress建站后怎样发布,网上购物商城排名,手机ppt制作在开发项目中#xff0c;避免不了不同页面之间传递数据等#xff0c;那么就需要进行不同页面之间的一个数据传递
直接传递一个对象时#xff1a;
页面A
gotoDetail(e){const music e.currentTarget.dataset.music;// 在小程序中#xff0c;不同页面之间如何进行参数传递…在开发项目中避免不了不同页面之间传递数据等那么就需要进行不同页面之间的一个数据传递
直接传递一个对象时
页面A
gotoDetail(e){const music e.currentTarget.dataset.music;// 在小程序中不同页面之间如何进行参数传递?// 既然不能传递对象所以需要将对象进行类型转换// encodeURIComponent : 将内容转换为编码wx.navigateTo({url:/pages/songDetail/songDetail?music encodeURIComponent(JSON.stringify(music)),});
},
页面B
Page({data:{},onLoad(options) {console.log( JSON.parse( decodeURIComponent( options.music ) ) );},
});
传递ID
但是通常情况下我们并不会将对象进行一个传递而是直接传递一个ID并在页面B中重新请求
wxml
进行传递参数 id“传递的值”来进行传递
data-* 自定义属性的设置 但是在后端使用的时候*的内容会全部变成小写
textwx:for{{recommendList}}wx:keyidclassiconfont icon-gengduodata-music{{item}}data-musicId{{item.id}}bindtapgotoDetail
/text
页面A
gotoDetail(e){const musicId e.currentTarget.dataset.musicid;wx.navigateTo({url:/pages/songDetail/songDetail?musicId musicId,});
},
页面B
Page({data: {},onLoad(options){console.log(options.musicId);},
});