小編給大家分享一下微信小程序中如何實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)傳參,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
實(shí)現(xiàn)的功能是給列表增加點(diǎn)擊功能傳參到下一頁(yè);
代碼如下:
<import src="../WXtemplate/headerTemplate.wxml"/> <view> <!--滾動(dòng)圖--> <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>
這里只為下面的列表增加了點(diǎn)擊方法
點(diǎn)擊列表js代碼
listClick:function(event){ console.log(event); var p = event.currentTarget.id wx.navigateTo({url:'/pages/xiangqing/xiangqing?id=上一頁(yè)的參數(shù)'}) }
其中
wx.navigateTo({url:'/pages/xiangqing/xiangqing?id=上一頁(yè)的參數(shù)'})
為跳轉(zhuǎn)方法,id為需要傳的參數(shù) 如果參數(shù)為動(dòng)態(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值
在下一頁(yè)取值代碼如下:
data:{ // text:"這是一個(gè)頁(yè)面" title:'' }, onLoad:function(options){ // 頁(yè)面初始化 options為頁(yè)面跳轉(zhuǎn)所帶來(lái)的參數(shù) this.setData({ title:options.id })
然后在頁(yè)面上顯示代碼如下:
<view>{{title}}</view>
最終實(shí)現(xiàn)效果:
以上是“微信小程序中如何實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)傳參”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
文章名稱:微信小程序中如何實(shí)現(xiàn)頁(yè)面跳轉(zhuǎn)傳參-創(chuàng)新互聯(lián)
網(wǎng)站URL:http://newbst.com/article8/hhiop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、關(guān)鍵詞優(yōu)化、軟件開(kāi)發(fā)、虛擬主機(jī)、App開(kāi)發(fā)、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容