微信小程序 頁面跳轉(zhuǎn)傳參詳解
微信小程序 頁面跳轉(zhuǎn)傳參,做微信小程序必定會用的這樣的功能,這里就記錄下本人學(xué)習(xí)實現(xiàn)代碼資料。
剛接觸微信小程序,多里面的語法和屬性還不怎么聊解,如有不多的地方希望各位大神多多指教。今天來說下微信小程序怎么跳轉(zhuǎn)和傳參,話不多說直接上代碼。
實現(xiàn)的功能是給列表增加點擊功能傳參到下一頁;

代碼如下:
<import src="../WXtemplate/headerTemplate.wxml"/>
<view>
<!--滾動圖-->
<view>
<swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoPlay}}" interval="{{intervalTime}}" duration="{{Time}}">
<block wx:for="{{imageURl}}">
<swiper-item>
<image src="{{item}}" class="imagePX"></image>
</swiper-item>
</block>
</swiper>
</view>
<!--功能按鈕-->
<view class="section-bg">
<block wx:for="{{buttonNum}}">
<!--模版-->
<template is="buttonList" data="{{item}}"/>
<!--<view class="section-item">
<image class="section-img" src="{{item.image}}"></image>
<text class="section-text">{{item.text}}</text>
</view>-->
</block>
</view>
<!--資訊列表-->
<view>
<block wx:for="{{listNum}}">
<template is="newList" data="{{item,index}}"/>
</block>
</view>
</view>
其中
<template is="buttonList" data="{{item}}"/>
為模版代碼如下
<template name="buttonList">
<view class="section-item">
<image class="section-img" src="{{item.image}}" bindtap="buttonClick"></image>
<text class="section-text">{{item.text}}</text>
</view>
</template>
<!--list-->
<template name="newList">
<view class="section-list" bindtap="listClick" id="{{index}}">
<view>
<image class="list-img" src="{{item.image}}"></image>
</view>
<view class="section-textt">
<view class="title"><text>{{item.title}}</text></view>
<view class="subTitle"><text>{{item.subTitle}}</text></view>
</view>
</view>
</template>
這里只為下面的列表增加了點擊方法
點擊列表js代碼
listClick:function(event){
console.log(event);
var p = event.currentTarget.id
wx.navigateTo({url:'/pages/xiangqing/xiangqing?id=上一頁的參數(shù)'})
}
其中
wx.navigateTo({url:'/pages/xiangqing/xiangqing?id=上一頁的參數(shù)'})
為跳轉(zhuǎn)方法,id為需要傳的參數(shù) 如果參數(shù)為動態(tài)參數(shù)代碼如下:
listClick:function(event){
console.log(event);
var p = event.currentTarget.id
wx.navigateTo({url:'/pages/xiangqing/xiangqing?id='+p})
}
其中p為上面為每一行設(shè)置的id值
在下一頁取值代碼如下:
data:{
// text:"這是一個頁面"
title:''
},
onLoad:function(options){
// 頁面初始化 options為頁面跳轉(zhuǎn)所帶來的參數(shù)
this.setData({
title:options.id
})
然后在頁面上顯示代碼如下:
<view>{{title}}</view>
最終實現(xiàn)效果:

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
微信小程序 中wx.chooseAddress(OBJECT)實例詳解
這篇文章主要介紹了微信小程序 中wx.chooseAddress(OBJECT)實例詳解的相關(guān)資料,需要的朋友可以參考下2017-03-03
JS實現(xiàn)一個可以當(dāng)鏡子照的?Button
這篇文章主要介紹了JS實現(xiàn)一個可以當(dāng)鏡子照的?Button的方法示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03
JavaScript節(jié)點的增刪改查深入學(xué)習(xí)
這篇文章主要為大家介紹了JavaScript節(jié)點的增刪改查深入學(xué)習(xí)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01
微信小程序組件 contact-button(客服會話按鈕)詳解及實例代碼
這篇文章主要介紹了微信小程序組件 contact-button(客服會話按鈕)詳解及實例代碼的相關(guān)資料,需要的朋友可以參考下2017-01-01

