页面跳转,传递数据

在home.wxml文件中定义绑定方法

...
<view class="service-preview" wx:for="{
     
     {serviceList}}" wx:key="index">
	<i-service-preview service_item="{
     
     {item}}" bind:tap="handleSelectService"
					data-service="{
     
     {item}}"></i-service-preview>
</view>
...

在home.json文件中跳转并传递数据

  handleSelectService: function (event) {
    
    
        const service = event.currentTarget.dataset.service
        //只传递一个id
        wx.navigateTo({
    
    
            url: "/pages/service-detail/service-detail?service_id=" + service.id
        })
    },

其中data-serviceconst service = event.currentTarget.dataset.service 中的service
两个service要相对应

在service-detail中接收数据

...
  onLoad: function (options) {
    
    
        const serviceId = options.service_id;
    },
 ...

猜你喜欢

转载自blog.csdn.net/xiaoduzi1991/article/details/125281332
今日推荐